ndim
numpy中获取数组的维度
import numpy as np
data1 = [1,2,3]
data2 = [[3,4,5],[6,7,8]]
data3 = [[[1,2,3],[4,5,6]],[[2,3,4],[5,6,7]]]
arr1 = np.array(data1)
arr2 = np.array(data2)
arr3 = np.array(data3)
ndim_1 = arr1.ndim
ndim_2 = arr2.ndim
ndim_3 = arr3.ndim
print(ndim_1) #1
print(ndim_2) #2
print(ndim_3) #3
shape
import numpy as np
x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]])
#输出数组的行和列数
print x.shape #结果: (4, 3)
#只输出行数
print x.shape[0] #结果: 4
#只输出列数
print x.shape[1] #结果: 3