I am fairly new to python and have started with 2.7 as that is what is used at work. I am trying to learn about interpolating. It is not going well. I am trying to import a list consisting of between 1000 and 6500 entries. That is easy enough.The hard part comes in when I'm trying to figure out how to insert 9 spaces between every item in the list and then interpolate the 9 steps between.
I want to end with a new text file being written. I can open, read, and write a new file. The stuff I need to do in the middle is looking out of reach. Everything I read about has a second array and I don't understand how I should configure one for my task, or if I need it. Any help would be greatly appreciated. FYI, the list of numbers being read in have 3 decimal places.
答案 0 :(得分:0)
这可以解决均匀间隔数据的问题。考虑将来发布一些自己的代码,以便根据您的确切难度量身定制答案。
from scipy import interpolate
import numpy as np
def interp_function(sx, sy, tau = 10):
sy_fnc = interpolate.splrep(sx, sy, s=0)
tau_interp = float(sx.max() - sx.min()) / float(tau * len(sx))
sx_interp = np.arange(sx[0], sx[len(sx)-1], tau_interp)
sy_interp = interpolate.splev(sx_interp, sy_fnc, der=0)
return sx_interp, sy_interp