Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何知道 numpy 数组/矩阵的最小值的(行、列)索引?
例如,如果A = array([[1, 2], [3, 0]]),我想得到(1, 1)
A = array([[1, 2], [3, 0]])
(1, 1)
谢谢!
使用unravel_index:
unravel_index
numpy.unravel_index(A.argmin(), A.shape)
[更正错字]
另一个简单的解决方案是
ri, ci = A.argmin()//A.shape[1], A.argmin()%A.shape[1]
由于 numpy.argmin 以行优先顺序返回索引读数
是的,你是对的,这是一个错字,适用于方阵