Return the number of dimensions of an array.
Input array. If it is not already an ndarray, a conversion is attempted.
The number of dimensions in a. Scalars are zero-dimensional.
See also
ndarray.ndimequivalent method
shapedimensions of array
ndarray.shapedimensions of array
>>> import numpy as np >>> np.ndim([[1,2,3],[4,5,6]]) 2 >>> np.ndim(np.array([[1,2,3],[4,5,6]])) 2 >>> np.ndim(1) 0
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.ma.ndim.html