codecaine icon

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

codecaine | PRO | 12/29/17 02:18:41 AM UTC | 0 ⭐ | 396 👁️ | Never ⏰ | []
Python |

270 B

|

None

|

0 👍

/

0 👎

import numpy as np
#numpy array of list values
values = np.array([1,4,7,1,9,1,10,1])
#number to search
searchNum = 1
#returns a list of where 1 is found in the list to foundIndexes
foundIndexes = np.where(values == searchNum)[0]
#print the results
print(foundIndexes)

Comments