如何在python numpy中获取特定值的数组col和row?

时间:2015-07-30 23:08:17

标签: python arrays numpy

我有一个这样的数组:

a = np.array([[23,31,42],[16,22,56],[33,11,51]])
b = a.min()
print a
print b

所以结果将是这样的:

 [[23 31 42]
  [16 22 56]
  [33 11 51]]
 11

如何在该数组中获取特定值的行和列?例如:

如果我想要值= b,其中b是11,那么我将得到2和1提醒a[2][1] = 11

在我的情况下,我需要获取数组中最低值的行和列。

1 个答案:

答案 0 :(得分:1)

你想要的是:

np.where(a == a.min())

如果a是一个浮点数组,则应该使用:

np.where(np.allclose(a, a.min()))