Skip to content

Instantly share code, notes, and snippets.

@teoliphant
teoliphant / simple_interpolation.py
Last active April 16, 2023 09:30
Vectorized linear interpolation
# The kernel function is
# roughtly equivalent to new[:] = np.interp(xnew, xvals, yvals)
# But this is broadcast so that it can be run many, many times
# quickly.
# Call using ynew = interp1d(xnew, xdata, ydata)
# ynew.shape will be xnew.shape
# Also, ydata.shape[-1] must be xdata.shape[-1]
# and if ydata or xdata have ndim greater than 1, the initial dimensions
# must be xnew.shape: