Python Forum

Full Version: Find Value in Array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hallo All

I find some value in array but i have not result, what's wrong with my code

VV = np.arange(min(dV),max(dV),.1)
for i in range(len(VV)):
    if VV[i] == 5.0:
       print("Values VV = ",VV[i])
       dIdVsat=xp1[i]
       break
You're working with floats and you should never compare floats on equality.
You can misuse np.searchsorted.
x = np.arange(1,10,.1)
# x is sorted
index = x.searchsorted(5)
# finds the index where to insert the value 5 to keep the order
print('Index:', index, 'Value:', x[index])
# prints the result
You should visit this page: https://0.30000000000000004.com/
OK, thank you very much for explained