如何使用scipy.interpolate.splrep插值曲线?

2024-10-01 15:41:24 发布

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

使用一些实验数据,我一辈子都无法想出如何使用splrep创建B样条曲线。数据在这里:http://ubuntuone.com/4ZFyFCEgyGsAjWNkxMBKWD

以下是摘录:

#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上的图: enter image description here

这是我的代码:

^{pr2}$

我知道我在做一件愚蠢至极的事,但我就是看不见。在


Tags: 数据代码comhttp温度曲线样条temperature
1条回答
网友
1楼 · 发布于 2024-10-01 15:41:24

你只需要从最小值到最大值:)。这对你来说应该不是个问题,@a different ben,但是请注意将来的读者,depth[indices]如果depth是一个列表而不是numpy数组,depth[indices]会抛出一个TypeError!在

>>> indices = np.argsort(depth)
>>> depth = depth[indices]
>>> temp = temp[indices]
>>> splrep(depth, temp)
(array([-7.05, -7.05, -7.05, -7.05, -5.03, -4.05, -3.  , -2.01, -1.01,
        1.  ,  1.  ,  1.  ,  1.  ]), array([ 16.0147    ,  15.54473241,  16.90606794,  14.55343229,
        15.12525673,  14.0717599 ,  15.19657895,  14.40437622,
        14.7036    ,   0.        ,   0.        ,   0.        ,   0.        ]), 3)

给@FerdinandBeyer的建议是argsort,而不是我丑陋的“压缩值,排序压缩,重新分配值”方法。在

相关问题 更多 >

    热门问题