1
採取我有三個矩陣爲這樣:更改順序np.argmax索引是從
one = np.empty((5,5))
one[:] = 10
two = np.empty((5,5))
two[:] = 10
three = np.empty((5,5))
three[:] = 2
我然後將它們堆疊:
stacked = np.dstack([one, two, three])
,最後確定與所述最大值的索引:
t_max = np.argmax(stacked, axis=2)
我現在想確定最大值,但有一個警告。如果有多個具有相同最大值的深度(如我的示例),我想從最大深度返回索引。
由於它現在是t_max
回報:
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]
但我想返回:
[[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]]
由於第二深度具有相同的最大值作爲第一,但具有較大的深度爲好。
編輯:
我想我可以做np.flip(stacked, axis=2)
第一,但也許這是不是最好的方法。