列值变化的行索引?

Row index by change in column value?

有这样的数组:

[[0 1 0]
 [0 1 1]
 [0 1 1]
 [1 0 0]]

如何选择列第一次变为1的行索引。 因为有 3 列,所以我必须获得 3 行索引。

在这种情况下:0,1,3

您可以将 numpy.argmaxaxis==0 一起使用:

ind = arr.argmax(axis=0)
ind.sort() # sort if needed
ind

输出:

array([0, 1, 3])