Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find Value in Array
#1
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
Reply
#2
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/
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
OK, thank you very much for explained
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020