ndim
ndim is a term used to describe the number of dimensions, or axes, of an array or tensor. It indicates the dimensionality of the data and influences how the object can be indexed, reshaped, and broadcasted in computations.
In NumPy, ndim is exposed in two closely related ways. The attribute ndarray.ndim on an array returns
Examples help illustrate ndim. A scalar produced by numpy.array(5) has shape () and ndim 0. A 1-D vector
ndim can change through operations that add or remove axes. For example, numpy.expand_dims increases ndim by
Notes and usage. numpy.ndim is convenient for generic code that accepts array-like inputs, while arr.ndim is
Other libraries use similar concepts with different names. For instance, PyTorch tensors have a ndim attribute