- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 UnivariateSpline 函数为某些数据(原始布拉格峰)生成拟合。这是我的代码:
import matplotlib.pyplot as plt
from scipy import interpolate
import numpy as np
spline = interpolate.UnivariateSpline(xi, yi, s = 0)
measured_depth_i = np.linspace(0.4, 10.4, 1000)
measured_dose_i = spline(measured_depth_i)
plt.plot(measured_depth, measured_dose, 'ro', label='Original Points')
plt.plot(measured_depth_i, measured_depth_i, label='Interpolated Points' )
其中 xi =
[ 0.4 , 0.48, 0.63, 0.79, 0.93, 1.08, 1.22, 1.38,
1.53, 1.68, 1.83, 1.99, 2.14, 2.29, 2.43, 2.59,
2.73, 2.89, 3.04, 3.19, 3.34, 3.48, 3.64, 3.8 ,
3.94, 4.09, 4.24, 4.39, 4.55, 4.7 , 4.85, 5. ,
5.15, 5.3 , 5.45, 5.59, 5.75, 5.9 , 6.05, 6.21,
6.35, 6.5 , 6.66, 6.8 , 6.95, 7.11, 7.24, 7.4 ,
7.55, 7.71, 7.86, 8. , 8.16, 8.31, 8.46, 8.61,
8.76, 8.91, 9.06, 9.22, 9.36, 9.52, 9.67, 9.81,
9.97, 10.12, 10.27, 10.4 ]
和 yi =
[ 2.16457961e+01, 2.16457961e+01, 2.16010733e+01,
2.18470483e+01, 2.20483005e+01, 2.22942755e+01,
2.24731664e+01, 2.26967800e+01, 2.29427549e+01,
2.30545617e+01, 2.32781753e+01, 2.34570662e+01,
2.36583184e+01, 2.37924866e+01, 2.39713775e+01,
2.42620751e+01, 2.44856887e+01, 2.46869410e+01,
2.49552773e+01, 2.51341682e+01, 2.53577818e+01,
2.56932021e+01, 2.58497317e+01, 2.61404293e+01,
2.63864043e+01, 2.65876565e+01, 2.68559928e+01,
2.72361360e+01, 2.74821109e+01, 2.78622540e+01,
2.81529517e+01, 2.84436494e+01, 2.88461538e+01,
2.91815742e+01, 2.95617174e+01, 3.00089445e+01,
3.04114490e+01, 3.09033989e+01, 3.13059034e+01,
3.18872987e+01, 3.24463327e+01, 3.31395349e+01,
3.37656530e+01, 3.44364937e+01, 3.51296959e+01,
3.60017889e+01, 3.68515206e+01, 3.78801431e+01,
3.91323792e+01, 4.04293381e+01, 4.19946333e+01,
4.37164580e+01, 4.57513417e+01, 4.83228980e+01,
5.16100179e+01, 5.58363148e+01, 6.13595707e+01,
6.93202147e+01, 8.35420394e+01, 1.00000000e+02,
8.47271914e+01, 3.60688730e+01, 6.21645796e+00,
3.35420394e-01, 2.23613596e-02, 2.23613596e-02,
2.23613596e-02, 2.23613596e-02]
我的插值曲线似乎仍然是一条直线,并且与我的数据完全不匹配,无论我的 s 值如何变化。谁能解释为什么我不能很好地适应我的数据?
最佳答案
诀窍是在绘图语句中正确获取变量名称:
spline = interpolate.UnivariateSpline(xi, yi, s = 0)
measured_depth_i = np.linspace(0.4, 10.4, 1000)
measured_dose_i = spline(measured_depth_i)
plt.plot(xi, yi, 'ro', label='Original Points')_
plt.plot(measured_depth_i, measured_dose_i, label='Interpolated Points' )_
结果图如下:
关于python - 将 UnivariateSpline 与 SCIPY 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25151547/
我正在研究一个简单的函数来拟合 yield 曲线。我正在使用 Scipy.interpolate.UnivariateSpline 来完成任务。该函数应返回特定时间间隔(到期日)的 yield 值。
我有一堆代表 sigmoidal 函数的 x, y 点: x=[ 1.00094909 1.08787635 1.17481363 1.2617564 1.34867881 1.43562
我正在使用 UnivariateSpline 为我拥有的一些数据构造分段多项式。然后我想在其他程序(C 或 FORTRAN 中)中使用这些样条,因此我想了解生成的样条背后的方程式。 这是我的代码: i
我正在尝试将一些 MatLab 代码移植到 Scipy,并且我尝试了 scipy.interpolate 中的两个不同函数,interp1d和 UnivariateSpline . interp1d
我尝试使用 SciPy 的平滑单变量样条 from scipy.interpolate import UnivariateSpline spl = UnivariateSpline(x, y) 我收到
我在尝试使用 UnivariateSpline 函数插入数据时遇到了一个奇怪的问题。通过所有点进行插值 (s=0) 和样条函数不会给出整个数据集的结果。 s>=1 的结果也很奇怪。因为我认为它与我正在
scipy UnivariateSpline 不允许多值 X。我读到这已更改,但似乎对我不起作用。我用的是最新版本,刚刚用pip尝试下载,说我有最新版本。 我曾尝试将 s(平滑)从 0 和 None(
我正在尝试使用 UnivariateSpline 函数为某些数据(原始布拉格峰)生成拟合。这是我的代码: import matplotlib.pyplot as plt from scipy impo
我正在尝试使用 SciPy 的 UnivariateSpline 来定位曲线上的一个点。不幸的是,我的结果是 nan。 这是一个最小的例子: from scipy.interpolate import
我无法让 scipy.interpolate.UnivariateSpline 在插值时使用任何平滑。基于function's page以及一些previous posts ,我相信它应该使用 s 参
我正在将用 R 编写的脚本移植到 Python。在 R 中,我使用 smooth.spline,在 Python 中,我使用 SciPy UnivariateSpline。它们不会产生相同的结果(即使
我有一个实验数据,我正在尝试使用 scipy 中的 UnivariateSpline 函数拟合曲线。数据如下: x y 13 2.404070 12 1.588134 1
当 spline = UnivariateSpline(x, y, bbox=[0,1], k=3.0,s=0.0) 对比 spline = UnivariateSpline(x, y, k=3.0,
scipy.interpolate.splrep(x, y, w=None, xb=None, xe=None, k=3, task=0, s=None, t=None, full_output=0,
我正在使用 scipy.interpolate.UnivariateSpline平滑地插入大量数据。效果很好。我得到一个像函数一样运行的对象。 现在我想保存样条点以备后用,并在不需要原始数据的情况下在
我是一名优秀的程序员,十分优秀!