Numpy的Linspace无法运行

2024-06-26 00:07:24 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我从数据文件中插值得到一个函数。后来,我使用linspace创建x值,然后将其插入到函数中。然而,当我这样做的时候,x范围扩大到100。我不明白它为什么这么做。我该怎么解决这个问题?enter image description here

x = np.loadtxt("/Users/shawn/Desktop/VDFDensityfinalz.dat", unpack = True)
y = np.loadtxt("/Users/shawn/Desktop/VDFDensityfinalshift.dat", unpack = True)
f = interp1d(x, y, kind = 'cubic')
xnew = np.linspace(0.0414, 1.0414,100)
plt.plot(f(xnew))

Tags: 函数true数据文件npusersdat插值desktop