Scipy interpolation on a numpy array

Posted by dassouki on Stack Overflow See other posts from Stack Overflow or by dassouki
Published on 2010-06-16T20:42:00Z Indexed on 2010/06/17 0:12 UTC
Read the original article Hit count: 725

Filed under:
|
|
|

I have a lookup table that is defined the following way:

TR_ua1 = np.array([ [3.6, 6.5, 9.1, 11.5, 13.8],
                    [3.9, 7.3, 10.0, 13.1, 15.9],
                    [4.5, 9.2, 12.2, 14.8, 18.2] ])
  • The header row elements are (hh) <1,2,3,4,5+
  • The header column (inc) elements are <10000, 20000, 20001+

The user will input a value ex (1.3, 25,000) or (0.2, 50,000). Scipy.interpolate() should interpolate to determine the correct value.

Currently, the only way i can do this is with a bunch of if/elifs as exemplified below. I'm pretty sure there is a better, more efficient way of doing this

Here's what i've got so far

import numpy as np
from scipy import interplate

if (ua == 1):
    if (inc <= low_inc): #low_inc = 10,000
      if (hh <= 1):
        return TR_ua1[0][0]
      elif (hh >= 1 & hh < 2):
        return interpolate( (1,2), (TR_ua1[0][1], TR_ua1[0][2]) )

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner