Python获取数组行数和列数的方法:
import numpy as np x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]]) # 输出数组的行和列数 <a href="https://www.gaodaima.com/tag/print" title="查看更多关于print的文章" target="_blank">print</a> x.<a href="https://www.gaodaima.com/tag/shape" title="查看更多关于shape的文章" target="_blank">shape</a> # (4, 3) # 只输出行数 print x.shape[0] # 4 # 只输出列数 print x.shape[1] # 3
www#gaodaima.com来源[email protected]搞@^&代*@码网搞代码
shape函数是numpy.core.fromnumeric中的函数,它的功能是查看矩阵或者数组的维数。
shape[0] 表示第一维 行数
shape[1] 表示第二维 列数
推荐学习:《Python教程》
来源:搞代码网:原文地址:https://www.gaodaima.com