core.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:soif 作者: ceyzeriat 项目源码 文件源码
def quantile(x, q, weights=None):
    """
    Like numpy.percentile, but:
    * Values of q are quantiles [0., 1.] rather than percentiles [0., 100.]
    * scalar q not supported (q must be iterable)
    * optional weights on x
    """
    if weights is None:
        return np.percentile(x, [100. * qi for qi in q])
    else:
        idx = np.argsort(x)
        xsorted = x[idx]
        cdf = np.add.accumulate(weights[idx])
        cdf /= cdf[-1]
        return np.interp(q, cdf, xsorted).tolist()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号