I used the numpy dot function to calculate the product of a 2D and a 1D array. I noticed that when the 2D array is of type matrix while the 1D array is of type ndarray, the result returned by the dot function is not the same as when I pass it a 2D array of type ndarray.
Question: Why are the results different?
Short example
import numpy as np
a=[[1,2],
[3,4],
[5,6]]
e=np.array([1,2])
b=np.array(a)
print("Ndarrray:%s"%(type(b)))
print(b)
print("Dim of ndarray %d"%(np.ndim(b)))
be=np.dot(b,e)
print(be)
print("Dim of array*array %d\n"%(np.ndim(be)))
c=np.mat(a)
print("Matrix:%s"%(type(c)))
print(c)
print("Dim of matrix %d"%(np.ndim(c)))
ce=np.dot(c,e)
print(ce)
print("Dim of matrix*array %d"%(np.ndim(ce)))
Ndarrray:<class 'numpy.ndarray'>
[[1 2]
[3 4]
[5 6]]
Dim of ndarray 2
[ 5 11 17]
Dim of array*array 1
Matrix:<class 'numpy.matrix'>
[[1 2]
[3 4]
[5 6]]
Dim of matrix 2
[[ 5 11 17]]
Dim of matrix*array 2
ā