[Python] Linear Interpolation speed : Numpy vs Pandas

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a 1d-lookup table of 100 rows. each y value corresponds to x value and I want to do interpolation between values of x data which are 0 decimal places so they are natural numbers basically. I want to achieve something like this

    y = [1,2,3,4,.....100]
    x = [2.1124 , 2.3243 ,2.3412 , 2.3423 , .... 3.5980]

    Whats value of y = 1.2 ? , 1.8 , 4.5 ?


    I am stuck between three options because of speed issues :

    1- I use linear piecewise interpolation first to get all possible 1 decimal place vlaues between 1 to 100 so the table will be of 1000 rows then. I store this in a numpy array in the code and query a value within this array when needed.

    2- I use pandas library and call this .csv file which has got these 1000 rows of data and everytime get the value from there.

    3- or I create a interpolation function that will do the linear interp in the asked range using scipy library . for eg if x value is 2.3415 then the function will automatically interpolate between y = 4 and 5 as this x value (2.3415) is in the nearest range of these y values

    which method will be faster to execute, I am going to use this feature in a code that will run live (continously)

    Continue reading...

Compartilhe esta Página