1
votes

I am trying to multiply these 1 dimensional matrices( or vectors) with each other as follows :

a = np.array([1,2,3]).reshape(1,3)

b = np.array([4,5,6]).reshape(1,3)

c = np.dot(a,b)

print(c) outputs ab error as 'shapes (1,3) and (1,3) not aligned' which are correct as per the matrix multiplication laws.

But when I do c = a*b and print(c) I get a 1 x 3 matrix - array([[ 4, 10, 18]]).

my question is how 1 X 3 * 1 X 3 matrix multiplication is yielding a 1 X 3 matrix ? Columns of first matrix should equal the rows of second. Isn't it?

Moreover, it would be great if any of you can shed some more info on how a dot product of 2 matrices of shapes(i,j) differs from its multiplication a*b?

1
(1,3), (3,1) would be correct matrix-multiplication. dot will do matmul then. The multipy-operator on the other hand is elementwise.sascha

1 Answers

1
votes

The dot method performs a matrix multiplication like you'd expect. The * operator takes two matrices of the same dimensions and multiplies their corresponding elements, thus producing a result of the same dimensions.