# Numpy Array vs Vector

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 :
import numpy as np

In :
arr0 = np.random.randn(4)
arr0

Out:
array([ 0.87942377, -0.69131025,  0.33220169,  1.76007805])
In :
arr0.shape

Out:
(4,)

The above is rank 1 or 1 dimensional array but this is neither a row or column.

let us create another array.

In :
arr1 = np.random.randn(4).T
arr1

Out:
array([-0.45719195,  0.78906387, -0.15142986, -0.3826037 ])
In :
arr1.shape

Out:
(4,)

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 :
res = np.dot(arr0,arr1)
res

Out:
-1.6712710262811714

Note dot product didn't generate a matrix but a number only.

Let us repeat the above steps for Numpy Vector now.

In :
arr0 = np.random.randn(4,1)
arr0

Out:
array([[ 1.12964633],
[ 1.29681385],
[-0.53971566],
[-0.17936079]])

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 :
arr0.shape

Out:
(4, 1)

As we can see shape is 4,1 that is 4 rows and one column

In :
arr1 = np.random.randn(1,4)
arr1

Out:
array([[-0.06850754, -0.01908695, -1.0186154 , -1.15776782]])
In :
arr1.shape

Out:
(1, 4)
In :
res = np.dot(arr0,arr1)
res

Out:
array([[-0.07738929, -0.02156151, -1.15067516, -1.30786817],
[-0.08884152, -0.02475222, -1.32095457, -1.50140934],
[ 0.03697459,  0.01030153,  0.54976269,  0.62486542],
[ 0.01228757,  0.00342345,  0.18269966,  0.20765815]])

res is a numpy matrix.