This notebook explains the difference between Numpy Array and Vector.
If you are new to Numpy, please checkout numpy basics tutorial first.
Let us create a numpy array.
In [1]:
importnumpyasnp
In [2]:
arr0=np.random.randn(4)arr0
Out[2]:
In [3]:
arr0.shape
Out[3]:
The above is rank 1 or 1 dimensional array but this is neither a row or column.
let us create another array.
In [4]:
arr1=np.random.randn(4).Tarr1
Out[4]:
In [5]:
arr1.shape
Out[5]:
For arr1, even though we applied the transpose, it is still a simple array without any row or column property.
Now let us calulate dot product.
In [6]:
res=np.dot(arr0,arr1)res
Out[6]:
Note dot product didn't generate a matrix but a number only.
Let us repeat the above steps for Numpy Vector now.
In [7]:
arr0=np.random.randn(4,1)arr0
Out[7]:
Even though it is still array but note the difference, two square brackets vs one in numpy array earlier. Let us print the shape.
In [8]:
arr0.shape
Out[8]:
As we can see shape is 4,1 that is 4 rows and one column
In [9]:
arr1=np.random.randn(1,4)arr1
Out[9]:
In [10]:
arr1.shape
Out[10]:
In [11]:
res=np.dot(arr0,arr1)res
Out[11]:
res is a numpy matrix.