我想根据prob给定行指定的概率分布随机选择样本点。ValueError: Fewer non-zero entries in p than size但是,当我调用 时,我收到错误np.random.choice。甚至是什么意思size?我也查看了实现,但我不明白。谢谢你的帮助!!
import numpy as np
# prob is a numpy array of shape (14, 6890)
all_zero = np.where(prob.max(1) < 1e-6)[0] # find indices of rows where all values are smaller
prob[all_zero] = 1 / prob.shape[1] # fill those rows uniformly
prob /= prob.sum(axis=1, keepdims=True)
# ... somewhere later inside a method
for j in range(14):
sample = np.random.choice(6890, 4, replace=False, p=prob[j]) # …Run Code Online (Sandbox Code Playgroud) 我查了一下,有一些帖子,例如this one,建议使用,torch.gesv但我似乎无法在 PyTorch 文档中找到它。