9951 explained code solutions for 126 technologies


python-numpyFind Numpy array index by value


import numpy as np
a = np.array([1,1,2,1,2])
indexes = np.where(a == 2)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

[1,1,2,1,2]

sample array

where(

returns indexes of found elements from array based on condition

a == 2

sample condition (search for elements with value 2)