我编写了一个程序来计算外尔群的根。但是,我收到以下错误。
Traceback (most recent call last):
File "./rootsAn.py", line 58, in <module>
equals = isequal(x[0],y[0])
TypeError: 'int' object is unsubscriptable
我已经查过了这个错误,但据我所知,x[0]
并且y[0]
都是数组,而不是ints
. 我的代码是:
def innerprod(a,b):
x = 0
y = 0
while x < len(a):
y += a[x]*b[x]
x += 1
return y
def isequal (a,b):
x = len(a)- 1
y = 0
counter = 0
while y < x:
if a[y] == a[x]:
counter+=1
else:
counter +=0
y += 1
if counter == x:
return True
else:
return False
simplerootsht = []
simpleroots = []
positiverootsht=[]
positiveroots = []
dim = 3
n = 0
while n < dim-1:
x = []
s = 0
while s < dim:
if s == n:
x.append(1)
elif s == n + 1:
x.append(-1)
else:
x.append(0)
s += 1
simplerootsht.append([x,1])
simpleroots.append(x)
n += 1
for c in simpleroots:
positiveroots.append(c)
for d in simplerootsht:
positiverootsht.append(d)
print positiverootsht
for x in positiverootsht:
for y in simplerootsht:
equals = isequal(x[0],y[0])
if equals == True:
pass
print x[0], y[0]
b = innerprod(x[0], y[0])
a = len(x[0])
if b == 0:
pass
else:
r = x[1]
q = r - b
print r, q
x = 1
while x < q:
z = [sum(pair) for pair in zip(x[0], x*y[0])]
if z not in positiveroots:
positiveroots.append(z)
positiverootsht.append([z,x[1] + y[1]])
x += 1
谢谢!