tags:

views:

3035

answers:

1

Hi, I have a set of data's as,

Table-1 
    X1    | Y1
    ------+--------
    0.1   | 0.52147
    0.02  | 0.8879 
    0.08  | 0.901
    0.11  | 1.55 
    0.15  | 1.82
    0.152 | 1.95

Table-2
    X2   | Y2
    -----+------
    0.2  | 0.11
    0.21 | 0.112
    0.34 | 0.120  
    0.33 | 1.121

I have to interpolate Table-2 'Y2' value for Table-1 'X1' value like,

    X1     |  Y2
    -------+-------
    0.1    |
    0.02   |
    0.08   |
    0.11   |
    0.15   |
    0.152  |

Note: Both Table-1 & 2 are unequal intervals with number of (X | Y) entries will differ, for eg. here we have 6 (X1 | Y1) entries in Table-1 and only 4 (X2 | Y2) in Table-2

Please help me which interpolation algorithm to use in Numpy, and how to proceed?

+6  A: 

numpy.interp seems to be the function you want: pass your X1 as the first argument x, your X2 as the second argument xp, your Y2 as the third argument fp, and you'll get the Y values corresponding to the X1 coordinates (looks like you want to completely ignore the existing Y1, right? this is what this does - otherwise you'll have to clarify your question much better explaining what role you have in might for the Y1's!).

If you want more than linear interpolation, I suggest you see scipy.interpolate and its tutorial rather than trying to stretch numpy beyond its simplicity;-).

Alex Martelli
NP, see my edited answer for pointers to scipy code that supports non-linear interpolation.
Alex Martelli