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)
| 3175 | |
| 3176 | @array_function_dispatch(_ndim_dispatcher) |
| 3177 | def 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 | |
| 3214 | def _size_dispatcher(a, axis=None): |