我有以下代码:
import numpy as np
sample = np.random.random((10,10,3))
argmax_indices = np.argmax(sample, axis=2)
Run Code Online (Sandbox Code Playgroud)
即我沿轴= 2取argmax,它给我一个(10,10)矩阵.现在,我想分配这些索引值0.为此,我想索引样本数组.我试过了:
max_values = sample[argmax_indices]
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我想要类似的东西
max_values = sample[argmax_indices]
sample[argmax_indices] = 0
Run Code Online (Sandbox Code Playgroud)
我只是通过检查确定max_values - np.max(sample, axis=2)应该给出零形状矩阵(10,10)来验证.任何帮助将不胜感激.