I know there is a method for a Python list to return the first index of something:
>>> xs = [1, 2, 3] >>> xs.index(2) 1
Is there something like that for NumPy arrays?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, given an array,
array, and a value,itemto search for, you can usenp.whereas:The result is a tuple with first all the row indices, then all the column indices.
For example, if an array is two dimensions and it contained your item at two locations then
would be equal to your item and so would be: