-1
我想为下面每行的特定列编号。 d
是类似于(embedding_id x n_vocab)
和t
的数据是正确embedding_id的列表。numpy中每一行的特定列
然后,我可以创建result
像下面一样。数据很好,但我认为这并不聪明。如何以其他智能方式创建result
?
t = np.random.randint(10, size=(32,))
d = np.random.randn(30, 32)
result = []
for a,b in zip(d.transpose(), t):
print(a[b])
result.append(a[b]) # I don't think this is good way
result = np.array(result).astype(float)
print(result)
print(result.shape) # (32,).
这是伟大的。可以肯定的是,第一个元素“t”是一个特定的列号,第二个元素是特定的行。所以我想要做的是为每一行提取特定列的值。我会接受你的回答。谢谢! – jef
你的理解是正确的。除了我会说't'是行索引,而第二个列索引按照惯例。 – Psidom