【发布时间】:2021-03-10 06:54:18
【问题描述】:
假设我有来自 Pytorch 或 Keras 预测的概率,结果是使用 softmax 函数
from scipy.special import softmax
probs = softmax(np.random.randn(20,10),1) # 20 instances and 10 class probabilities
probs
我想从这个 numpy 数组中找到前 5 个索引。我想做的就是在结果上运行一个循环,例如:
for index in top_5_indices:
if index in result:
print('Found')
如果我的结果在前 5 个结果中,我会得到。
Pytorch 有top-k 功能,我见过numpy.argpartition,但我不知道如何完成?
【问题讨论】:
标签: python numpy keras pytorch