简体   繁体   中英

interpolate function - matrix

Do you know about similar function to this where points are narrays (matrix)?

I try to convert function from matlab:

Ex=interp3(X,Y,Z,squeeze(Emat(1,:,:,:)),x(1),x(2),x(3), 'linear', 0);

to python. Tried:

Ex=interpn((X,Y,Z), np.squeeze(Emat[1,:,:,:]), np.array(x))

but X, Y, Z should be tuple of ndarray of float, while in matlab is has shape 12 12 12.

Are you looking for something along these lines?

import numpy as np
import matplotlib.pyplot as plt

def linear_approx(x,xf1,xf2):
    (x1,f1) = xf1
    (x2,f2) = xf2
    return f1*(x-x2)/(x1-x2) + f2*(x-x1)/(x2-x1)

x1, f1 = 0.0, 3.0
x2, f2 = 2.0, -2.0

plt.plot(x1,f1,"ro")
plt.plot(x2,f2,"ro")

myx = np.linspace(-1,4,200)
plt.plot(myx,linear_approx(myx,(x1,f1),(x2,f2)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM