def interp_mat(x, xp):
    u_ixps = np.interp(x, xp, range(len(xp)))
    m = np.zeros((len(x), len(xp)))
    for ix, u_ixp in enumerate(u_ixps):
        u, ixp = np.modf(u_ixp)
        m[ix, ixp] = 1.-u
        if ixp+1 < m.shape[1]: # the last u is zero by definition
            m[ix, ixp+1] = u
    return m
interp_mat(x, xp).dot(fp) should be the same as np.interp(x, xp, fp)
dataset/ETHPy150Open rll/lfd/lfd/rapprentice/math_utils.py/interp_mat