I was trying to locate the index of a value on a numpy array (same for hundreds of them) using np.where. Its not that slow but its a bottleneck so i began experimenting with fortran and f2py and wrote this simple routine.
subroutine find_index(array1, num_elements, target_value, loc)
real, intent(in) :: array1(:)
integer, intent(in) :: num_elements, target_value
integer, intent(out) :: loc
do i = 1, num_elements
if (array1(i) .eq. target_value) then
loc = i
exit
endif
end do
end subroutine
But still no improvement (same as np.where). So i guess its about the method. any sugestions on improving the code (python or fortran)?
EDIT the values i am searching for are integers in an array of integers