binnings.py 文件源码

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

项目:physt 作者: janpipek 项目源码 文件源码
def numpy_binning(data, bins=10, range=None, *args, **kwargs):
    """Construct binning schema compatible with numpy.histogram

    Parameters
    ----------
    data: array_like, optional
        This is optional if both bins and range are set
    bins: int or array_like
    range: Optional[tuple]
        (min, max)
    includes_right_edge: Optional[bool]
        default: True

    Returns
    -------
    NumpyBinning

    See Also
    --------
    numpy.histogram
    """
    if isinstance(bins, int):
        if range:
            bins = np.linspace(range[0], range[1], bins + 1)
        else:
            start = data.min()
            stop = data.max()
            bins = np.linspace(start, stop, bins + 1)
    elif np.iterable(bins):
        bins = np.asarray(bins)
    else:
        # Some numpy edge case
        _, bins = np.histogram(data, bins, **kwargs)
    return NumpyBinning(bins)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号