np.sum() #计算数组的和
    np.mean() #返回数组中元素的算数平均值
    np.average() #根据在另一个数组中给出的各自的权重计算数组中元素的加权平均值
    np.std() #计算数组标准差
    np.var() #计算数组方差
    np.min() #计算数组中的元素沿指定轴的最小值
    np.max() #计算数组中的元素沿指定轴的最大值
    np.argmin() #返回数组最小元素的索引
    np.argmax() #返回数组最大元素的索引
    np.cumsum() #计算所有元素的累计和
    np.cumprod() #计算所有元素的累计积
    np.ptp() #计算数组中最大值与最小值的差(最大值-最小值)
    np.median() #计算数组中元素的中位数(中值)

    1. import numpy as np
    2. score = np.array([[80,88],[82,81],[75,82]])
    3. #1、获取所有数据最大值
    4. result1 = np.max(score)
    5. print(result1)
    6. #2、获取某一个轴上的数据最大值
    7. result2 = np.max(score,axis = 0)
    8. print(result2)
    9. #3、获取所有数据最小值 #4、获取某个轴上的数据最小值
    10. #5、数据的比较
    11. result5 = np.maximum([-2,-1,0,1,2],0)
    12. #第一个参数中的每个数与第二个参数比较返回大的
    13. print(result5)
    14. result6 = np.minimum([-2,-1,0,1,2],0)
    15. #第一个参数中的每个数与第二个参数比较返回大的
    16. print(result6)
    17. result7 = np.maximum([-2,-1,0,1,2],[1,2,3,4,5])
    18. #接受的两个参数,也可以大小一致;第二个参数只是一个单独的值时,其实用到了维度的广播机制
    19. print(result7)
    1. 88
    2. [82 88]
    3. [0 0 0 1 2]
    4. [-2 -1 0 0 0]
    5. [1 2 3 4 5]
    1. import numpy as np
    2. score = np.array([[80,88],[82,81],[75,82]])
    3. #6、求平均值
    4. result6 = np.mean(score) #获取所有数据的平均值
    5. result7 = np.mean(score,axis = 0) #获取某个轴上的平均值
    6. print(result6)
    7. print(result7)
    8. #7、返回给定axis上的累计和
    9. arr1 = np.array([[1,2,3],[4,5,6]])
    10. print(arr1)
    11. print(arr1.cumsum(0)) #axis=0 相同列累计和
    12. print(arr1.cumsum(1)) #axis=1 相同行累计和
    1. 81.33333333333333
    2. [79. 83.66666667]
    3. [[1 2 3]
    4. [4 5 6]]
    5. [[1 2 3]
    6. [5 7 9]]
    7. [[ 1 3 6]
    8. [ 4 9 15]]
    1. #8、argmin求最小值索引
    2. result = np.argmin(score,axis = 0)
    3. print(result)
    4. #9、求每一列的标准差
    5. #标准差事一组数据平均值分散程度的一种度量。一个较大的标准差,代表大部分数值和其平均值之间差异较大;
    6. #一个较小标准差,代表这些数据较接近平均值反应出数据的波动稳定情况,越大表示波动越大越不稳定。
    7. result = np.std(score,axis = 0)
    8. print(result)
    9. #10、极值
    10. #np.ptp(t,axis=None)就是最大值和最小值的差
    11. #拓展:方差var,协方差cov,计算平均值 average,计算中位数median
    1. [2 1]
    2. [2.94392029 3.09120617]

    numpy.argmax()和numpy.argmin()函数分别给沿着指定轴返回最大和最小元素的索引:

    1. import numpy as np
    2. a = np.array([[30,40,70],[80,20,10],[50,90,60]])
    3. #调用 argmax()函数
    4. np.argmax(a)
    5. #展开数组:
    6. a.flatten()
    7. #沿着轴 0 的最大值索引
    8. maxindex = np.argmax(a,axis=0)
    9. maxindex
    10. #沿着轴1 的最大值索引
    11. maxindex = np.argmax(a,axis = 1)
    12. maxindex
    13. #调用argmin()函数:
    14. minindex = np.argmin(a)
    15. minindex
    16. #展开数组中的最小值:
    17. a.flatten()[minindex]
    18. #沿轴0 的最小值索引:
    19. minindex = np.argmin(a,axis = 0)
    20. minindex
    21. #沿轴1 的最小值索引
    22. minindex = np.argmin(a,axis = 1)
    23. minindex
    1. array([0, 2, 0], dtype=int64)