shape: 获取数组的形状
假设是一个二维数组
shape[0]: 获取数组的行数
shape[1]: 获取数组的列数
例:
import numpy as np x = np.array([[1, 2, 3, 4], [4, 3, 2, 1]]) print(x.shape) print(x.shape[0]) print(x.shape[1])
输出:
(2, 4) 2 4

shape: 获取数组的形状
假设是一个二维数组
shape[0]: 获取数组的行数
shape[1]: 获取数组的列数
例:
import numpy as np x = np.array([[1, 2, 3, 4], [4, 3, 2, 1]]) print(x.shape) print(x.shape[0]) print(x.shape[1])
输出:
(2, 4) 2 4