import numpy as np
x = np.array([[1, 2, 5], [2, 3, 5], [3, 3, 5], [4, 3, 5]])
#输出数组
print(x)
#输出数组的行数和列数
print(x.shape)
#输出数组的行数
print(x.shape[0])
#输出数组的列数
print(x.shape[2])
通过安装导入numpy库,矩阵(ndarray)的shape 可以获得矩阵的行数和列数
import numpy as np
x = np.array([[1, 2, 5], [2, 3, 5], [3, 3, 5], [4, 3, 5]])
#输出数组
print(x)
#输出数组的行数和列数
print(x.shape)
#输出数组的行数
print(x.shape[0])
#输出数组的列数
print(x.shape[2])
通过安装导入numpy库,矩阵(ndarray)的shape 可以获得矩阵的行数和列数