如何在numpy 2D数组中获得第二个最小值的索引?

时间:2018-03-23 03:02:09

标签: python arrays numpy minimum

a=array([[ 0.  ,  0.71,  5.66,  3.61,  4.24,  3.2 ],
   [ 0.71,  0.  ,  4.95,  2.92,  3.54,  2.5 ],
   [ 5.66,  4.95,  0.  ,  2.94,  1.41,  2.5 ],
   [ 3.61,  2.92,  2.94,  0.  ,  1.  ,  0.5 ],
   [ 4.24,  3.54,  1.41,  1.  ,  0.  ,  1.12],
   [ 3.2 ,  2.5 ,  2.5 ,  0.5 ,  1.12,  0.  ]])

row,column=np.unravel_index(a.argmin(), a.shape)

返回row = 0,column = 0。我想要第二个最小值的行和列,我们行= 3,列= 5或行= 5,列= 3.

0 个答案:

没有答案