The *
operator for numpy arrays is element wise multiplication (similar to the Hadamard product for arrays of the same dimension), not matrix multiply.
For example:
>>> a
array([[0],
[1],
[2]])
>>> b
array([0, 1, 2])
>>> a*b
array([[0, 0, 0],
[0, 1, 2],
[0, 2, 4]])
For matrix multiply with numpy arrays:
>>> a = np.ones((3,2))
>>> b = np.ones((2,4))
>>> np.dot(a,b)
array([[ 2., 2., 2., 2.],
[ 2., 2., 2., 2.],
[ 2., 2., 2., 2.]])
In addition you can use the matrix class:
>>> a=np.matrix(np.ones((3,2)))
>>> b=np.matrix(np.ones((2,4)))
>>> a*b
matrix([[ 2., 2., 2., 2.],
[ 2., 2., 2., 2.],
[ 2., 2., 2., 2.]])
More information on broadcasting numpy arrays can be found here, and more information on the matrix class can be found here.