Re: Simple Interpolation in Numpy?

Discussion in 'Python' started by Steve Holden, Feb 8, 2007.

  1. Steve Holden

    Steve Holden Guest

    LAPI, VINCENT J, ATTLABS wrote:
    > Hi,
    > Please bear with me as I am new to Python and have not done any
    > programming in about 20 years. I am attempting to do a simple
    > interpolation of a line's intermediate points given the x,y coordinates
    > of the line's two endpoints within an Active State Python script that I
    > am working with. Is there a simple way to do this simple interpolation
    > in the Active state Python 2.4 that I have or do I need to get Numeric
    > Python? And where do I get it?
    > Thanks,
    > Vince Lapi
    >

    You shouldn't really *need* Numeric (NumPy or numpy, nowadays) for a
    relatively simple problem like that, since the formulae involved are
    pretty simple.

    Given known points on the line at (xa, ya) and (xb, yb) then for any
    point (x, y) on the line we get

    y = ya + ((x - xa) * (yb - ya))/(xb - xa)

    So you just need to plug the values for x and the known points into the
    formula to get the interpolated value of y.

    If you are interpolating a non-linear formula through a number of
    samples clearly there'd be a little more jiggery pokery involved to
    identify the particular interval on which interpolation is required, but
    nothing horrendous.

    Numpy, which is derived from the old Numeric code, is at

    http://numpy.scipy.org/

    should you wish to investigate its features. It probably has
    better-than-linear interpolation algorithms in it. Note that if you
    decide to download it you should choose the Python 2.4 version -
    extensions coded in compiled languages are specific to a particular
    version of the language.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    Blog of Note: http://holdenweb.blogspot.com
    See you at PyCon? http://us.pycon.org/TX2007
     
    Steve Holden, Feb 8, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drife
    Replies:
    1
    Views:
    396
    Travis E. Oliphant
    Mar 1, 2006
  2. Hendrik van Rooyen

    Re: Simple Interpolation in Numpy?

    Hendrik van Rooyen, Feb 9, 2007, in forum: Python
    Replies:
    0
    Views:
    428
    Hendrik van Rooyen
    Feb 9, 2007
  3. Duncan Smith
    Replies:
    3
    Views:
    452
    Duncan Smith
    Apr 25, 2007
  4. Replies:
    2
    Views:
    520
    Robert Kern
    Nov 13, 2007
  5. W. eWatson
    Replies:
    2
    Views:
    1,054
    W. eWatson
    Nov 23, 2009
Loading...

Share This Page