MCPcopy Create free account
hub / github.com/numpy/numpy / ndim

Function ndim

numpy/core/fromnumeric.py:3177–3211  ·  view source on GitHub ↗

Return the number of dimensions of an array. Parameters ---------- a : array_like Input array. If it is not already an ndarray, a conversion is attempted. Returns ------- number_of_dimensions : int The number of dimensions in `a`. Scalars are

(a)

Source from the content-addressed store, hash-verified

3175
3176@array_function_dispatch(_ndim_dispatcher)
3177def ndim(a):
3178 """
3179 Return the number of dimensions of an array.
3180
3181 Parameters
3182 ----------
3183 a : array_like
3184 Input array. If it is not already an ndarray, a conversion is
3185 attempted.
3186
3187 Returns
3188 -------
3189 number_of_dimensions : int
3190 The number of dimensions in `a`. Scalars are zero-dimensional.
3191
3192 See Also
3193 --------
3194 ndarray.ndim : equivalent method
3195 shape : dimensions of array
3196 ndarray.shape : dimensions of array
3197
3198 Examples
3199 --------
3200 >>> np.ndim([[1,2,3],[4,5,6]])
3201 2
3202 >>> np.ndim(np.array([[1,2,3],[4,5,6]]))
3203 2
3204 >>> np.ndim(1)
3205 0
3206
3207 """
3208 try:
3209 return a.ndim
3210 except AttributeError:
3211 return asarray(a).ndim
3212
3213
3214def _size_dispatcher(a, axis=None):

Callers 1

linspaceFunction · 0.70

Calls 1

asarrayFunction · 0.70

Tested by

no test coverage detected