2
votes

I'm trying to convert some matlab code to python code with the numpy lib. The code search in arrays values and save the found indexes

the original matlabcode

index1 = find(array1 == 2 & array2 > array3);

my python "translation"

index1 = np.where((array1 == 2) & (array2 > array3))

is this the correct way? I can't test the output because I have no matlab, I hope someone can help me with that. Thanks!

1
Test it on a test array and see if it does what you want.wwii

1 Answers

1
votes

try

np.nonzero( np.logical_and( array1 == 2, array2 > array3 ) )

You can read more about logical_and and nonzero. You might also consider replacing nonzero() with flatnonzero