find function matlab in numpy/scipy

前端 未结 1 2041
名媛妹妹
名媛妹妹 2021-02-15 06:19

Is there an equivalent function of find(A>9,1) from matlab for numpy/scipy. I know that there is the nonzero function in numpy but what I need is th

相关标签:
1条回答
  • 2021-02-15 06:57

    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] 
    

    But if all you are looking for is finding the first element that satisfies a condition, you are better off using max.

    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()
    
    0 讨论(0)
提交回复
热议问题