我正在尝试实现原始高斯,并在执行时获得不支持的操作数类型错误。 输出:
execfile(filename, namespace)
File "/media/zax/MYLINUXLIVE/A0N-.py", line 26, in <module>
print Naive_Gauss([[2,3],[4,5]],[[6],[7]])
File "/media/zax/MYLINUXLIVE/A0N-.py", line 20, in Naive_Gauss
b[row] = b[row]-xmult*b[column]
TypeError: unsupported operand type(s) for -: 'list' and 'list'
>>>
这是密码
def Naive_Gauss(Array,b):
n = len(Array)
for column in xrange(n-1):
for row in xrange(column+1, n):
xmult = Array[row][column] / Array[column][column]
Array[row][column] = xmult
#print Array[row][col]
for col in xrange(0, n):
Array[row][col] = Array[row][col] - xmult*Array[column][col]
b[row] = b[row]-xmult*b[column]
print Array
print b
print Naive_Gauss([[2,3],[4,5]],[[6],[7]])
在Python中使用Set
需要执行的操作,需要通过
或者可以通过
如上所述,两个列表作为操作数输入,它触发错误。
不能从列表中减去列表。
简单的方法是使用^{} :
您也可以使用列表理解,但需要更改函数中的代码:
相关问题 更多 >
编程相关推荐