python如何判断多维数组多少列
yang
2020-04-05 11:22:286939浏览 · 0收藏 · 0评论
Python获取数组行数和列数的方法:
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
shape函数是numpy.core.fromnumeric中的函数,它的功能是查看矩阵或者数组的维数。
shape[0] 表示第一维 行数
shape[1] 表示第二维 列数
推荐学习:《Python教程》
关注公众号,随时随地在线学习