I am trying to find a suitable python function to replace matlab findin my script and with some google search, which I see np.where(), solves the goal most of the time. But in the case of a double state, I have different results. Can someone tell me what is wrong with this approach and how to move on? Sample code and the difference below.
In the case of matlab:
b = [1, 2, 3; 1, 2, 3; 1, 2, 3]
[I, J] = find(( b > 1) & (b <= 3))
Produces output
I = J =
1 2
2 2
3 2
1 3
2 3
3 3
In the case of python:
b= array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
>>> np.where((b > 1) & (b <= 3))
(array([0, 0, 1, 1, 2, 2]), array([1, 2, 1, 2, 1, 2]))
source
share