np.mean以及np.std用法
np.mean()是用来计算均值,np.std()是用来计算标准差。下面是mean的用法,std同理。
先写一个矩阵:
1 import numpy as np 2 3 4 X = np.array([[1,2], [4, 5], [7, 8]]) 5 print(X)
输出:
1、axis = 0 计算矩阵每一列的平均值,显示结果为行向量
1 import numpy as np 2 X = np.array([[1,2], [4, 5], [7, 8]]) 3 X = np.mean(X, axis = 0) 4 print(X)
输出:
2、axis = 1 计算矩阵每一行的平均值,显示结果为列向量
1 import numpy as np 2 X = np.array([[1,2], [4, 5], [7, 8]]) 3 X = np.mean(X, axis = 1) 4 print(X)
输出:
参考:https://www.jianshu.com/p/155ab3984596