0
最近我遇到了一些我不太明白的Numpy练习。练习以3D阵列使用一些随机样本数据:什么时候是:相当于Numpy中的完整索引向量?
import numpy as np
alpha = np.full(2000, .1)
beta = np.full(100, .1)
wordsInTopic = np.random.dirichlet(alpha, 100)
produced = np.zeros((50, 100, 2000))
for doc in range(0, 50):
topicsInDoc = np.random.dirichlet(beta)
wordsToTopic = np.random.multinomial(2000, topicsInDoc)
for topic in range(0, 100):
produced[doc, topic] = np.random.multinomial(wordsToTopic[topic], wordsInTopic[topic])
例如下面是等价的,因为预期:
print(produced[:, np.arange(0, 100, 1), :].shape)
print(produced[:, :, :].shape)
但以下是不:
print(produced[:, np.arange(0, 100, 1), produced.sum(0).argmax(1)].shape)
print(produced[:, :, produced.sum(0).argmax(1)].shape)
有人能解释这里发生了什么吗?
':'指定沿轴的每个索引,就这些了。 –
您正在触发前者的高级索引。去谷歌上查询。 – Divakar