Multiplying matrices

To do matrix multplication in the standard sense, use the np.dot() function.

>>> A = np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> B = np.array([[1,0,-1],[2,0,-2],[3,0,-3]])
>>> print(A)
[[1 2 3]
 [4 5 6]
 [7 8 9]]
>>> print(B)
[[ 1  0 -1]
 [ 2  0 -2]
 [ 3  0 -3]]
>>> np.dot(A,B)
array([[ 14,   0, -14],
       [ 32,   0, -32],
       [ 50,   0, -50]])

The * operation multiplies the arrays element by element, which is not what we usually want:

>>> A*B
array([[  1,   0,  -3],
       [  8,   0, -12],
       [ 21,   0, -27]])