Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bisect
- class InterpTable(object):
- '''
- a look up table that linearly interperlates between values
- '''
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def __getitem__(self, v):
- j = bisect.bisect_left(self.x, v)
- i = j-1
- if i < 0 :
- return self.y[0]
- if j >= len(self.x) :
- return self.y[ -1 ]
- return self.y[i] + (v-self.x[i])*(self.y[j]-self.y[i])/(self.x[j]-self.x[i])
Add Comment
Please, Sign In to add comment