2

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
  • 1
    Test it on a test array and see if it does what you want. Commented Nov 20, 2014 at 16:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.