3
使用一些实验数据,我不能在我的生活中找到如何使用splrep创建B样条。该数据在这里:http://ubuntuone.com/4ZFyFCEgyGsAjWNkxMBKWD如何使用scipy.interpolate.splrep插入曲线?
下面是摘录:
#Depth Temperature
1 14.7036
-0.02 14.6842
-1.01 14.7317
-2.01 14.3844
-3 14.847
-4.05 14.9585
-5.03 15.9707
-5.99 16.0166
-7.05 16.0147
,这里是它与深入y和温度X上的一个情节:
这里是我的代码:
import numpy as np
from scipy.interpolate import splrep, splev
tdata = np.genfromtxt('t-data.txt',
skip_header=1, delimiter='\t')
depth = tdata[:, 0]
temp = tdata[:, 1]
# Find the B-spline representation of 1-D curve:
tck = splrep(depth, temp)
### fails here with "Error on input data" returned. ###
我知道我在做什么bleedingly愚蠢的,但我就是不能看到它。
你或许应该使用'np.argsort()'函数来排序的数据:'指数= np.argsort(深度);深度=深度[指数]; temp = temp [indices]'。这为您节省了元组列表的绕行。 – 2012-04-16 08:24:12
@FerdinandBeyer这是一个比我的更好的解决方案!现在编辑它。 – 2012-04-16 08:25:11
当我试图做'深度[指数]'时,我得到了一个错误,但是请让我知道是否有比'[深度[我]在指数中]更好的方式“。无论哪种方式,这是一个更清洁的解决方案,谢谢。 – 2012-04-16 08:31:23