python numpy np.percentile

"""
np.percentile获取中位数、百分位数
给定一个递增数组a,求它的中位数。
np.percentile(a,50)
中位数就是50%处的数字,也可以获得0%、100%处的数字,0%处的数字就是第一个数字,100%处的数字就是最后一个数字。
1/(len(a)-1)*100处的数字就是第2个数字,2/(len(a)-1)*100处的数字就是第3个数字,以此类推。
np.percentile()函数的作用就是求百分位数,从而能够知道数字大致的分布。
percentile函数原型为:
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False)
        a是原始数组,可以是多维数组
        q为0~100之间的浮点数或者浮点数组,若为浮点数组表示批量查询
        axis:在a的哪个轴上计算百分位数
"""
import numpy as np

a = np.array([1, 2, 3, 4, 5, 6, 7])
print("np.percentile(a, 50):", np.percentile(a, 50))
print("np.percentile(a, 5):", np.percentile(a, 5))

b = np.array([[1, 2, 3, 4, 5, 6, 7],
              [8, 9, 10, 11, 12, 13, 14]])
b = np.array([[10, 7, 4],
              [3, 2, 1]])
print("np.percentile(b, [0,100]):", np.percentile(b, [0,100]))


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值