我有一个热编码的M x N
矩阵A
,具有以下属性:
M
<<N
我还需要一个M x 1
数组B
,它包含整数(即我要选择的随机样本数)。B
的每个单元格都具有以下属性:
B[i]
<;=np.sum(M[i])
我正在寻找最有效的方法来随机抽取A
的每一行中的一个子集。为每行返回的样本数由B
的相应单元格中的整数值给出。输出将是一个M x N
矩阵,我们称之为C
,其中B == np.sum(C, axis=1)
A = np.array([[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 1],
[1, 0, 0, 1, 1, 0, 0, 0]])
B = np.array([1, 3, 2])
运行此算法的有效输出为
array([[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0]])
另一个可能的结果是
array([[0, 0, 0, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 1, 1, 0, 0, 0]])
寻找尽可能快地生成X
随机样本的能力
这个怎么样
输出:
相关问题 更多 >
编程相关推荐