Videos
Hi. I'm just learning python coming from matlab, and need to do some linear algebra for a program I'm writing. Naturally I am using numpy, but I'm very confused by how it handles matrix multiplication. The normal rules say that for an M by N matrix, multiplication is only defined if you right-multiply by an N by P matrix. yet I'm finding that it seems to want to do M by N with P by N.
e.g:
import numpy as np
a = np.asarray([0, 1, 2])
b = np.asarray([3, 4, 5])
print(np.matmul(a,b))
>>> 14
this seems wrong. This should be undefined since the # rows on the right don't match the # columns on the left. Is there an implicit transposition going on here? If this is truly how this is supposed to operate this way, it seems like it is flirting with disaster since it is will not produce the result that convention dictates it should, and for square matrices will make it very hard to track down where in your code your matrix multiplication got screwed up, since no error will get thrown. Am I missing something here?