You can get the dimension of the NumPy array with the following code. If you want to learn Python, I highly recommend reading This Book.
Example 1
import numpy as np a = np.array([5, 10, 15, 20]) print(a.ndim)
Output:
1
Example 2
import numpy as np a = np.array(5) print(a.ndim)
Output:
0
Example 3
import numpy as np a = np.array([[5, 10, 15],[20, 25, 30]]) print(a.ndim)
Output:
2
Example 4
import numpy as np a = np.array([[[5, 10, 15],[20, 25, 30],[35, 40, 45]]]) print(a.ndim)
Output:
3
Example 5
import numpy as np a = np.array([[ [[5, 10, 15]],[[20, 25, 30]],[[35, 40, 45]] ]]) print(a.ndim)
Output:
4
People are also reading:
What is Computer Vision? Examples, Applications, Techniques
Books for Machine Learning (ML)