更新时间:2023-02-26 15:41:41
numpy中find
的等效项是nonzero
,但它不支持第二个参数.
但是您可以执行类似的操作来获得您想要的行为.
The equivalent of find
in numpy is nonzero
, but it does not support a second parameter.
But you can do something like this to get the behavior you are looking for.
B = nonzero(A >= 9)[0]
但是,如果您要寻找的是找到满足条件的第一个元素,那么***使用max
.
But if all you are looking for is finding the first element that satisfies a condition, you are better off using max
.
例如,在matlab中,find(A >= 9, 1)
将与[idx, B] = max(A >= 9)
相同. numpy中的等效函数如下.
For example, in matlab, find(A >= 9, 1)
would be the same as [idx, B] = max(A >= 9)
. The equivalent function in numpy would be the following.
idx = (A >= 9).argmax()