Advertisements
Advertisements
Question
What do you understand by rank of an ndarray?
Short Answer
Advertisements
Solution
The rank of an ndarray means the number of dimensions (axes) present in the array. It tells us whether the array is one-dimensional, two-dimensional, three-dimensional, and so on.
- A 1-dimensional array has rank 1.
- A 2-dimensional array has rank 2.
- A 3-dimensional array has rank 3.
import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a.ndim)
Output:
2
Therefore, the rank of the given ndarray is 2.
shaalaa.com
Is there an error in this question or solution?
