小编Ray*_*iaz的帖子

python numpy argmax to multi in multidimensional array

我有以下代码:

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)来验证.任何帮助将不胜感激.

python numpy max multidimensional-array argmax

4
推荐指数
1
解决办法
5291
查看次数

标签 统计

argmax ×1

max ×1

multidimensional-array ×1

numpy ×1

python ×1