python中,可以用以下函数来判断numpy数组的维度:
- ndarray.ndim:返回数组的维数(轴数)。
- ndarray.shape:返回一个元组,表示每个维度的大小。
- ndarray.size:返回数组中元素的总数。
>>> import numpy as np
>>> a=np.zeros((4,8))
>>> print(a)
[[0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0.]]
>>> print(np.ndim(a))
2
>>> print(np.shape(a))
(4, 8)
>>> print(np.size(a))
32