3 回答

TA贡献1906条经验 获得超10个赞
如果你想要的结果是一个 4x2 数组,它索引三个数组中哪个位置的最大值,i,j那么你想要使用np.argmax
>>> import numpy as np
>>> predict_prob1 =([[0.95602106, 0.04397894],
[0.93332366, 0.06667634],
[0.97311459, 0.02688541],
[0.97323962, 0.02676038]])
>>> predict_prob2 =([[0.70425144, 0.29574856],
[0.69751251, 0.30248749],
[0.7072872 , 0.2927128 ],
[0.68683139, 0.31316861]])
>>> predict_prob3 =([[0.56551921, 0.43448079],
[0.93321106, 0.06678894],
[0.92345399, 0.07654601],
[0.88396842, 0.11603158]])
>>> np.argmax((predict_prob1,predict_prob2,predict_prob3), 0)
array([[0, 2],
[0, 1],
[0, 1],
[0, 1]])
>>>
附录
阅读了 OP 的评论后,我将以下内容添加到我的答案中
>>> names = np.array(['predict_prob%d'%(i+1) for i in range(3)])
>>> names[np.argmax((predict_prob1,predict_prob2,predict_prob3),0)]
array([['predict_prob1', 'predict_prob3'],
['predict_prob1', 'predict_prob2'],
['predict_prob1', 'predict_prob2'],
['predict_prob1', 'predict_prob2']], dtype='<U13')
>>>

TA贡献1788条经验 获得超4个赞
你可以这样做np.maximum.reduce:
np.maximum.reduce([A, B, C])
其中A, B,C是numpy.ndarray
对于您的示例,它的结果是:
[[0.95602106 0.43448079]
[0.93332366 0.30248749]
[0.97311459 0.2927128 ]
[0.97323962 0.31316861]]

TA贡献1802条经验 获得超10个赞
假设您想要,对于每一行,类别 0 的概率最高的数组的索引:
which = 0
np.stack([predict_prob1, predict_prob2, predict_prob3], axis=2)[:, which, :].argmax(axis=1)
输出:
array([0, 0, 0, 0])
对于第 1 类:
array([2, 1, 1, 1])
添加回答
举报