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.
import numpy as np
arr0 = np.random.randn(4)
arr0
arr0.shape
The above is rank 1 or 1 dimensional array but this is neither a row or column.
let us create another array.
arr1 = np.random.randn(4).T
arr1
arr1.shape
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.
res = np.dot(arr0,arr1)
res
Note dot product didn't generate a matrix but a number only.
Let us repeat the above steps for Numpy Vector now.
arr0 = np.random.randn(4,1)
arr0
Even though it is still array but note the difference, two square brackets vs one in numpy array earlier. Let us print the shape.
arr0.shape
As we can see shape is 4,1 that is 4 rows and one column
arr1 = np.random.randn(1,4)
arr1
arr1.shape
res = np.dot(arr0,arr1)
res
res is a numpy matrix.
Related Notebooks
- How To Handle nan In Numpy
- Covid 19 Curve Fit Using Python Pandas And Numpy
- Polynomial Interpolation Using Python Pandas Numpy And Sklearn
- Convert Pandas DataFrame To Numpy Arrays
- Numpy Basics
- Python Numpy Where
- Understand Tensors With Numpy
- ERROR Could not find a version that satisfies the requirement numpy==1 22 3
- How To Solve Error Numpy Has No Attribute Float In Python