<分区>
是否可以将最大的 numpy 数组偏移量转换为元组?
例如,如果“array”是:
[[1 2 3 6 8],
[2 4 1 1 0],
[0 0 0 20 0]]
然后 np.max(array) 将返回 20,它的位置/偏移量是 array[2][3]。
有没有可能把array[2][3]变成tuple = (2,3)?
感谢您的输入。
<分区>
是否可以将最大的 numpy 数组偏移量转换为元组?
例如,如果“array”是:
[[1 2 3 6 8],
[2 4 1 1 0],
[0 0 0 20 0]]
然后 np.max(array) 将返回 20,它的位置/偏移量是 array[2][3]。
有没有可能把array[2][3]变成tuple = (2,3)?
感谢您的输入。
最佳答案
你正在寻找 unravel_index 和 argmax
import numpy as np
a = np.array([[1 2 3 6 8],
[2 4 1 1 0],
[0 0 0 20 0]])
np.unravel_index( a.argmax() , a.shape)
关于python - 将最大 numpy 数组偏移量转换为元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53088587/