我想根据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]) # error occurs here
侃侃无极
相关分类