aggregate_numpy.py 文件源码

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

项目:mobula 作者: wkcn 项目源码 文件源码
def _sum(group_idx, a, size, fill_value, dtype=None):
    dtype = minimum_dtype_scalar(fill_value, dtype, a)

    if np.ndim(a) == 0:
        ret = np.bincount(group_idx, minlength=size).astype(dtype)
        if a != 1:
            ret *= a
    else:
        if np.iscomplexobj(a):
            ret = np.empty(size, dtype=dtype)
            ret.real = np.bincount(group_idx, weights=a.real,
                              minlength=size)
            ret.imag = np.bincount(group_idx, weights=a.imag,
                              minlength=size)
        else:
            ret = np.bincount(group_idx, weights=a,
                              minlength=size).astype(dtype)

    if fill_value != 0:
        fill_untouched(group_idx, ret, fill_value)
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号