gpt4 book ai didi

python - RBF插值: LinAlgError: singular matrix

转载 作者:太空狗 更新时间:2023-10-29 22:30:50 26 4
gpt4 key购买 nike

下面的调用:

rbf = Rbf(points[0], points[1], values,epsilon=2)

导致错误:

LinAlgError: singular matrix

具有以下值:

In [3]: points
Out[3]:
(array([71, 50, 48, 84, 71, 74, 89, 76, 70, 77, 74, 79, 83, 71, 72, 78, 73,
84, 75, 65, 73, 82, 48, 86, 74, 86, 66, 74, 68, 74, 81, 74, 88, 66,
57, 50, 72, 86, 72, 92, 81, 67, 82, 78, 69, 70, 73, 71, 76, 72, 74,
75]),
array([32, 34, 4, 35, 1, 7, 47, 16, 37, 14, 65, 18, 32, 4, 3, 27, 25,
34, 18, 25, 6, 25, 34, 41, 16, 35, 44, 2, 32, 2, 37, 60, 45, 32,
33, 42, 54, 31, 18, 38, 24, 18, 45, 48, 9, 63, 56, 45, 9, 59, 5,
12]))

In [4]: values
Out[4]:
array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

我该怎么做才能避免它并仍然解决插值问题?

最佳答案

我想你想做的是 kernel density estimation .您可以使用 scipy.stats.gaussian_kde为此:

import numpy as np
from scipy.stats import gaussian_kde
from matplotlib import pyplot as pp

# kernel density estimate of the PDF
kde = gaussian_kde(points)

# evaluate the estimated PDF on a grid
x,y = np.mgrid[40:101,-20:101]
z = kde((x.ravel(),y.ravel())).reshape(*x.shape)

# plot
fig,ax = pp.subplots(1,1)
ax.hold(True)
pc = ax.pcolor(x,y,z)
cb = pp.colorbar(pc)
cb.ax.set_ylabel('Probability density')
ax.plot(points[0],points[1],'o',mfc='w',mec='k')

pp.show()

enter image description here

statsmodels模块还有 some more elaborate tools用于核密度估计。

关于python - RBF插值: LinAlgError: singular matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19237512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com