Replacing matlab search function in python

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]))
+4
source share
1 answer

Both methods provide the same answer, although the conditions for ordering and indexing are different.

The indexing of Python arrays begins with 0, as in C, whereas matlab begins with 1.

, ( matlab numpy) . , .

, Matlab , numpy .

+4

Source: https://habr.com/ru/post/1530263/


All Articles