numpy_helper.py 文件源码

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

项目:latenttrees 作者: kaltwang 项目源码 文件源码
def downsample_idx(N, N_max=100, axis=0, method='equidist'):
    if N > N_max:
        if method == 'equidist':
            step = (N - 1) / N_max
            idx_cont = (np.arange(N_max) + 0.5) * step

            # add small slope to idx-cont, to avoid rounding neighbouring values to the same integer.
            # max absolute value added/subtracted is 1/10 of the step size
            adjust = ((idx_cont * 2 / (N - 1)) - 1) * step / 10
            idx_cont += adjust

            idx = np.array(np.round(idx_cont), dtype=int)

        if method == 'random':
            idx = np.random.choice(N, size=N_max, replace=False)
            idx = np.sort(idx)
    else:
        idx = np.s_[:]
    return idx
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号