我无法让UnivariateSpline工作,也无法理解原因。这是我的代码
x = gg
y = AA
order = np.argsort(x)
s = UnivariateSpline(x[order], y[order],s=2)
xs =np.linspace(x.min(), x.max(),1000)
ys = s(xs)
print ys, xs
plt.plot(x, y, 'kx')
plt.plot(xs, ys)
plt.show()
我订购了x所以它正在增加,但是当我打印ys时它只生产了Nan,为什么会这样?我还包括了我的数据。
x = [0.87 0.87 1.03 1.11 1.73 1.35 1.06 0.96 0.95 0.88 1.93 1.47 0.86 1.11 1.11 0.87 1.6 1.49 1.69 1.69 1.45 1.27 1.44 1.02 1.55 0.89 1. 1.15 0.95 1.35 1.01 0.94 1.33 1.06 1.02 1.69 1.3 0.95 1.44 1.26 1.19 1.11 1.15 1.88 0.99 1.08 1.12 1.05 1.83 1.02 1.47 1.45 1.05 0.94 1.13 1.13 0.96 1.16 0.96 1. 1.27 1.59 0.93 0.95 0.98 1.28 1.15 1.07 1.13 1.03 1.11 1.239 1.62 1.47 1.33 1.09 1.07 1.32 1.66 1.34 1.2 1.33 1.36 0.91 1.16 1.11 1.19 0.81 0.848 1.08 1.303 1.15 0.978 0.793 1.182 1.144 1.028 1.414 1.154 0.971 1.582 1.69 0.84 1.68 1.563 1.31 0.96 1.645 1.562 1.115 1.744 0.91 0.68 0.933 1.346 0.965 1.058 1.23 0.981 0.811 1.274 1.492 0.905 1.148 0.962 1.864 1.029 1.433 1.29 0.996 1.087 1.808 1.708 1.296 0.987 1.04 1.39 1.284 1.203 1.384 1.381 1.494 1.475 0.95 0.979 1.243 1.693 1.056 0.987 1.637 0.927 1.104 1.727 1.091 0.683 0.888 1.312 1.286 1.383 1.39 0.963 1.399 1.775 1.708 1.394 1.08 1.22 1.309 0.882 0.938 0.827 1.239 1.08 0.993 1.414 1.543 1.384 1.397 1.309 0.813 0.905 1.308 1.097 1.222 1.806 1.373 1.04 1.953 1.014 1.053 1.744 1.078 0.999 0.958 1.362 1.25 1.105 1.212 1.08 1.1 1.15 1.04 1.93 1.3 1.06 1.93 1.47 1.66 1.87 0.79 1.47 1.01 0.99 1.39 1.02 1.26 0.88 1.039 1.56 1.56 1.28 1.46 1.49 1.15 1.05 1.32 1.69 1.13 1.04 1.22 1.32 1.13]
y = [ - 20.75773476 -21.95605805 -18.55369454 -20.67245856 -19.62696343 -19.55530858 -18.95608912 -19.64894855 -21.08583017 -19.67611242 -16.98516684 -19.52183042 -19.35861489 -19.45113249 -19.46748808 -19.56511028 -19.01836861 -19.07039287 -18.71520888 -18.5959465 -19.27673143 -18.46111878 -19.04900086 -19.46237401 -18.85288474 -18.94376487 -19.56129631 -18.25373565 -19.0402584 -19.11021341 -20.14313411 -19.0094892 -19.85736922 -19.32347224 -17.54212938 -18.20511008 -19.15334887 -19.4630462 -19.10668158 -19.12292187 -19.49888379 -18.98698548 -19.63296244 -17.43109707 -19.27344865 -19.72353021 -19.50492931 -19.01556334 -17.99341048 -19.82498055 -19.3700599 -18.9952582 -19.33534228 -19.06240718 -20.24151987 -18.6909794 -19.47474624 -19.376 -19.66818612 -18.48562058 -19.1816036 -18.73009615 -19.3802243 -19.65062917 -19.51094855 -19.27075625 -19.2643377 -19.50928051 -18.71288474 -19.00752556 -19.40530082 -18.66894989 -18.95206887 -19.11472505 -19.12601863 -19.69488474 -19.18050614 -19.51813053 -18.66365612 -19.06866347 -19.44236792 -19.3181134 -19.34606887 -19.69606887 -17.68377874 -19.48058667 -19.26539543 -19.59919024 -17.13415424 -18.22039643 -19.44696389 -18.81278115 -19.15695593 -19.25948629 -18.95651017 -17.82323224 -19.25454228 -18.90437568 -19.00375282 -19.33312158 -18.23805935 -16.13066692 -19.24173249 -18.43009615 -18.68278974 -18.76883915 -18.91382004 -18.91016051 -18.87812918 -18.97871676 -18.38917104 -18.87380696 -18.91447676 -19.36974539 -18.40749787 -18.7171065 -19.17753134 -18.6437204 -17.75627028 -19.22785715 -18.942218 -18.83139643 -18.57414917 -17.74068247 -17.39696523 -17.54715024 -18.94085716 -18.80297694 -17.4693065 -18.69845481 -19.24505873 -18.18606275 -18.41842275 -18.72615948 -19.24477489 -18.24605686 -19.12704995 -18.55301631 -19.02873324 -18.20360428 -19.01807643 -18.8576467 -16.72642346 -18.73290347 -19.57792461 -18.46440018 -16.75837926 -19.01840605 -18.84268086 -19.16249228 -19.1452556 -18.85670293 -16.61269149 -19.32322472 -19.61336086 -19.14713205 -19.00167389 -19.21950828 -18.57434855 -18.89538237 -19.1956379 -19.27185286 -18.26925481 -19.14838955 -17.24333935 -19.07210494 -18.59402238 -19.11365325 -19.15965481 -19.40565246 -19.29119889 -19.36227222 -18.88348 -19.00418308 -18.83466448 -18.70841888 -18.71623118 -18.78792767 -17.58485304 -18.76253556 -19.46880445 -19.68363138 -16.65476254 -18.91970674 -18.16549078 -18.94279389 -18.80437489 -18.06376891 -18.44935273 -19.27794347 -18.25822884 -19.06764426 -19.4229065 -17.69461134 -18.4704577 -18.7862643 -19.64512929 -19.49212929 -19.71412929 -18.56740838 -19.11224461 -19.07288479 -17.9825899 -19.04773481 -19.56360284 -17.9825899 -20.85540746 -16.72785864 -18.28513249 -19.33713249 -22.87091889 -21.13739543 -23.27644629 -19.58028995 -20.57171676 -19.11361694 -21.49140009 -8.49565849 -18.84206887 -18.96128036 -18.99272505 -18.78201863 -18.86486674 -19.85488474 -18.71650614 -19.42013053 -18.54165612 -18.82666347 -19.20436792 -19.1821134 -19.53206887 -18.37421924]
答案 0 :(得分:2)
参数s = 2(结数)出错 - 它对于您的数据来说非常小。 例如,它适用于s = 237,但不适用于236。 据我所知,它必须大于或等于观察数加上平滑样条的程度。