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
评论列表
文章目录