我试图矢量化以下代码:
for i in xrange(s.shape[0]): a[i] = np.argmax(np.random.multinomial(1,s[i,:]))
s.shape = 400 x 100 [给定].
s.shape = 400 x 100
a.shape = 400 [预期].
a.shape = 400
s是2D矩阵,包含对的概率.期望多项式从s矩阵的每一行中抽取随机样本并将结果存储在向量a中.
python numpy vectorization random-sample
numpy ×1
python ×1
random-sample ×1
vectorization ×1