This article mainly shows the commonly used statistical methods of arrays in python: summation, maximum value, average
1, summation
use the sum function to sum all or a certain axis of the elements in the array (all: sum(); some Axial: sum() axial)
arr888 = np.arange(6).reshape((2,3))
print("原始数组是:\n",arr888)
#求和运算
#全部求和
print("数组各个元素之和:\n",arr888.sum())
#第0轴方向求和
print("第0维方向之和:\n", arr888.sum(0))
#第1轴方向求和
print("第1维方向之和:\n", arr888.sum(1))
Operation result:
2. Find the maximum value
Use max() and min() to find the maximum and minimum values of all or a certain axis respectively:
arr888 = np.arange(6).reshape((2,3))
print("原始数组是:\n",arr888)
#最值
print("求全部元素的\n最大值:%d,最小值:%d"%(arr888.max(),arr888.min()))
print("求第0维元素的\n最大值:%s,最小值:%s"%(arr888.max(0), arr888.min(0)))
print("求第1维元素的\n最大值:%s,最小值:%s"%(arr888.max(1), arr888.min(1)))
Running results:
3. Find the average
Use the mean() function to view the arithmetic average of all elements in the array or a certain axis:
arr888 = np.arange(6).reshape((2,3))
print("原始数组是:\n",arr888)
#算术平均数
print("求全部元素的算术平均数:" ,arr888.mean())
print("求第0维元素的算术平均数:" ,arr888.mean(0))
print("求第1维元素的算术平均数:" ,arr888.mean(1))
operation result: