首页 > 解决方案 > 在 (0, 1) 轴上查找 3d 数组的唯一最大索引

问题描述

我正在尝试在 (0, 1) 轴上找到 3d 数组的最大索引。

我尝试将 argwhere 与 amax 一起使用,但如果它有多个最大值,它会在轴上返回多个索引

x = [[[ 4  5  9]
      [ 0 13  6]]

     [[12 11 13]
      [ 5 13  8]]]  

np.amax(x, axis=(0,1))
>> [12 13 13]  #I just want the indices of the following max values

x==np.amax(x, axis=(0,1))
#this seems to be the problem, multiple True in the second column
             v
>>[[[False False False]
    [False  True False]]

    [[True False  True]
     [False  True False]]]

np.argwhere(x==np.amax(x, axis=(0,1))) #this should return 3 indices instead of 4
>>[[0 1 1]
   [1 0 0]
   [1 0 2]
   [1 1 1]]

那么是否有任何“numpy 方式”来获取 3d 数组在 (0, 1) 轴上的唯一最大索引

标签: pythonnumpynumpy-ndarray

解决方案


推荐阅读