前提・実現したいこと
以下のようにscipyを用いて、線形補間を用いた2Dプロットを作成しようと考えています。
発生している問題・エラーメッセージ
python
1print(x, y, z)
[ 0. 0.0197 0.0399 ..., 0.0602 0.0402 0.0202] [ 150. 150. 150. ..., 1000. 1000. 1000.] [ 0.0038828 0.0016416 0.0033378 ..., 0.23935 0.2409 0.23913 ]
python
1import numpy as np 2import matplotlib.pyplot as plt 3import scipy.interpolate 4 5# Set up a regular grid of interpolation points 6xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100) 7xi, yi = np.meshgrid(xi, yi) 8 9# Interpolate 10rbf = scipy.interpolate.Rbf(x, y, z, function='linear') 11zi = rbf(xi, yi) 12 13plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower', 14 extent=[x.min(), x.max(), y.min(), y.max()]) 15plt.scatter(x, y, c=z) 16plt.colorbar() 17plt.show()
のようにすると、
LinAlgError Traceback (most recent call last)
<ipython-input-53-ceae274e1d6d> in <module>()
8
9 # Interpolate
---> 10 rbf = scipy.interpolate.Rbf(x, y, z, function='linear')
11 zi = rbf(xi, yi)
12
/opt/conda/lib/python3.5/site-packages/scipy/interpolate/rbf.py in init(self, *args, **kwargs)
220
221 self.A = self._init_function(r) - np.eye(self.N)*self.smooth
--> 222 self.nodes = linalg.solve(self.A, self.di)
223
224 def _call_norm(self, x1, x2):
/opt/conda/lib/python3.5/site-packages/scipy/linalg/basic.py in solve(a, b, sym_pos, lower, overwrite_a, overwrite_b, debug, check_finite)
101 return x
102 if info > 0:
--> 103 raise LinAlgError("singular matrix")
104 raise ValueError('illegal value in %d-th argument of internal gesv|posv' %
105 -info)
LinAlgError: singular matrix
とのエラーが出ます。
もしお分かりのかたがいましたらよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/19 11:56
2018/04/19 12:03
2018/04/19 12:16