codecaine

Find all indexes of a number in a list using numpy.array

Dec 28th, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. import numpy as np
  2. #numpy array of list values
  3. values = np.array([1,4,7,1,9,1,10,1])
  4. #number to search
  5. searchNum = 1
  6. #returns a list of where 1 is found in the list to foundIndexes
  7. foundIndexes = np.where(values == searchNum)[0]
  8. #print the results
  9. print(foundIndexes)
Add Comment
Please, Sign In to add comment