如何使用 python/numpy 计算百分位数? [英] How do I calculate percentiles with python/numpy?

查看:52
本文介绍了如何使用 python/numpy 计算百分位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方便的方法来计算序列或一维 numpy 数组的百分位数?

Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?

我正在寻找类似于 Excel 的百分位函数的东西.

I am looking for something similar to Excel's percentile function.

我查看了 NumPy 的统计参考,没有找到.我能找到的只是中位数(第 50 个百分位数),但不是更具体的.

I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something more specific.

推荐答案

您可能对 SciPy 统计 包.它有百分位函数 您正在寻找许多其他统计数据.

You might be interested in the SciPy Stats package. It has the percentile function you're after and many other statistical goodies.

percentile() 可用numpy 中也是.

import numpy as np
a = np.array([1,2,3,4,5])
p = np.percentile(a, 50) # return 50th percentile, e.g median.
print p
3.0

这张票让我相信他们不会整合percentile() 很快就会变成 numpy.

This ticket leads me to believe they won't be integrating percentile() into numpy anytime soon.

这篇关于如何使用 python/numpy 计算百分位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆