基本的にはGauss Elimination(Foward)
メソッドをコーディングしようとしていますが、実行時には2つのリスト間の減算が発生すると例外として、"Object has no attribute '__getitem__'"
が発生します。Gauss Elimination "オブジェクトに属性がありません__getitem__ '"
完全なスタックトレースは次のとおりです。
Traceback (most recent call last): File line 35, in <module> b=a.GaussForward() File line 29, in GaussForward self.a[index][w]=self.a[index][w]-aux[i][w] TypeError: 'float' object has no attribute 'getitem'
私は以下のコードを投稿します。
class TestGauss():
a=[]
def __init__(self,A):
self.a=A
def __getitem__(self,i):
return self.a[i]
def __setitem__(self,i,value):
self.a[i]=value
def GaussForward(self):
pivo=0.0
fact=0.0
aux=[]
for i in range(len(self.a)):
pivo=self.a[i][i]
for j in range(i+1,len(self.a[0])):
fact=self.a[j][i]/float(pivo)
print fact
for k in range(len(self.a[0])):
self.a[i][k]*=fact
for w in range(len(self.a[0])):
aux=self.a[i]
if i+1<len(self.a[0]):
index=i+1
self.a[index][w]=self.a[index][w]-aux[i][w]
print self.a
あなたの質問にスタックトレース全体を含めると便利です。 – dsh
ああ、私の悪い。 [W] = B = a.GaussForward() ファイルの29行目、GaussForwardで self.a [インデックス]で、 ファイルの行35:ここではスタックトレース(と思う).Traceback(最新の呼び出しの最後)でありますself.a [index] [w] -aux [i] [w] TypeError: 'float'オブジェクトに属性 '__getitem__'がありません –