In matrix multiplication, assume that the A
is a 3 x 2 matrix (3 rows, 2 columns ) and B
is a 2 x 4 matrix (2 rows, 4 columns ), then if a matrix C = A * B
, then C
should have 3 rows and 4 columns. Why does numpy not do this multiplication? When I try the following code I get an error : ValueError: operands could not be broadcast together with shapes (3,2) (2,4)
a = np.ones((3,2))
b = np.ones((2,4))
print a*b
I try with transposing A and B and alwasy get the same answer. Why? How do I do the matrix multiplication in this case?