import numpy as np
二维
y = np.array([[1,2,3],[4,5,6]])
print(y)
[[1 2 3]
[4 5 6]]print(y.shape) # 展示行数,列数
(2, 3)print(y.shape[0]) # 展示行数
print(y.shape[1]) # 展示列数
三维
x = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[0,1,2]],[[3,4,5],[6,7,8]]])
print(x)
[[[1 2 3]
[4 5 6]]
[[7 8 9]
[0 1 2]]
[[3 4 5]
[6 7 8]]]
print(x.shape) #展示 降维度出来的低维度个数,行数,列数
(3, 2, 3)print(x.shape[0]) # 降为出来的低维度个数
print(x.shape[1]) # 每个低维度数组的行数
print(x.shape[2]) # 每个低维度数组的列数
以看到x是一个包含了3个两行三列的二维数组的三维数组,x.shape[0]代表包含二维数组的个数,x.shape[1]表示二维数组的行数,x.shape[2]表示二维数组的列数。
可以看到,shape[0]表示最外围的数组的维数,shape[1]表示次外围的数组的维数,数字不断增大,维数由外到内。