[Numpy-discussion] Linear Interpolation Question

Andrea Gavana andrea.gavana@gmail....
Mon Apr 28 06:41:16 CDT 2008

Hi All,

   I have 2 matrices coming from 2 different simulations: the first
column of the matrices is a date (time) at which all the other results
in the matrix have been reported (simulation step). In these 2
matrices, very often the simulation steps do not coincide, so I just
want to interpolate the results in the second matrix using the dates
in the first matrix. The problem is, I have close to 13,000 columns in
every matrices, and repeating interp1d all over the columns is quite
expensive. An example of what I am doing is as follows:

# Loop over all the columns
for indx in indices:

    # Set up a linear interpolation with:
    # x = dates in the second simulation
    # y = single column in the second matrix simulation
    function = interp1d(secondaryMatrixDates,
secondaryMatrixResults[:, indx], kind='linear')

    # Interpolate the second matrix results using the first simulation dates
    interpolationResults = function(mainMatrixDates)

    # I need the difference between the first simulation and the second
    newMatrix[:, indx] = mainMatrixResults[:, indx] - interpolationResults

This is somehow a costly step, as it's taking up a lot of CPU
(increasing at every iteration) and quite a long time (every column
has about 350 data). Is there anything I can do to speed up this loop?
Or may someone suggest a better approach?

Thank you very much for your suggestions.


"Imagination Is The Only Weapon In The War Against Reality."

More information about the Numpy-discussion mailing list