This question has been asked before (see [1] and [2]) but I have yet to find an answer that does not involve writing a time-consuming for
loop. I have even tried structuring the problem a different way (see [3]) and was not able to achieve better results.
I would like to interpolate a 2D array at many different points. I have already tried using Scipy interp2d
, but when you call the resulting function on n points, it returns an nxn matrix rather than just n values.
I need a solution that will be very fast, as it will be called hundreds of thousands of times, on tens of thousands of points each time.
Edit: my real data is too large to post but this is a toy example:
# set up interpolation function
d = [[0, 0, 1, 2, 3], [0, 1, 2.5, 3, 4]]
s = [[0.5, 0.5, 0.5, 0.5, 0.5], [0.6, 0.6, 0.6, 0.6, 0.6]]
l = [[9,8,7,6,5],[9,8,7,6,5]]
fxn = interp2d(d,s,l)
# interpolate at list of points
# (same as input points in this example, not always true though)
print(fxn([1,2,1],[0.6,0.5,0.6]))
The result is:
[[7. 7. 6. ]
[8. 8. 7.2535014]
[8. 8. 7.2535014]]
Sure, if I take the left diagonal and re-sort according to the input values, I can get the expected answer [8, 6, 8]
but I'd like to avoid this computational overhead if I can.