import numpy as np
#统计分析函数
# n=np.array([[1,2,3],[4,5,6],[7,8,9]])
# print(n)
# print(n.sum(axis=0)) #axis=1按行 axis=0按列 不指定则算总和
# print(n.mean(axis=0)) #1 行 0 列 平均值
# print(n.max(axis=1)) #max(),min()
# price=np.array([34.5,36,37.8,39,39.8,33.6])
# number=np.array([900,580,230,150,120,1800])
# print(np.average(price,weights=number)) #average()加权平均数
# n=np.array([34.5,36,37.8,39,39.8,33.6])
# print(np.msort(n)) #sort()排序
# n1=sorted(n)
# print(np.median(n1)) #median()中位数
# print(np.var(n)) #var()数组方差 std()数组标准差
# n=np.array([[4,7,3],[2,8,5],[9,1,6]])
# print(n)
# print(np.sort(n,axis=0)) #1 行 0 列
# x=np.array([4,7,3,2,8,5,1,9,6])
# y=np.argsort(x) #argsort()返回升序排序后的索引值
# print(y)
# print(x[y]) #排序后的顺序重构原数组
math=np.array([101,109,115,108,118,118])
eng=np.array([117,105,118,108,98,109])
total=np.array([621,623,620,620,615,615])
sort_total=np.lexsort((eng,math,total)) #lexsort()多个序列排序
print(sort_total) # 排序后的索引值
print(np.array([[eng[i],math[i],total[i]] for i in sort_total])) #通过排序后的索引获取排序后的数组
numpy 统计分析函数
最新推荐文章于 2024-06-22 22:07:09 发布