shape()
返回数组或者数据框的维度
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
因此可以用来遍历行或者列
#计算每列的均值
ex=np.array(np.mean(x[:,i]) for i in range(x.shape[1]))