嘿,伙计们,我在运行代码时总是遇到这个错误
Traceback (most recent call last):
File "Jacobi.py", line 93, in <module>
limit, guess, statement = jacobi(sys.argv[1], sys.argv[2])
File "Jacobi.py", line 65, in jacobi
guess[0, i] = guess2[0, i]
OverflowError: Python int too large to convert to C long
我把我的代码贴在下面,有人能快速修复吗?它不会一直这样做只是在随机的情况下。有人知道为什么吗?在
^{pr2}$创建矩阵 elim=[aCols-1] N=np.删除(A,伊琳,1) A=N
for i in range (0, A.shape[0]):
for k in range (0, A.shape[0]):
A[i,k] = round((A[i,k]),7)
print(A)
print ('\n')
print(b)
tol = float(tolIn)
#Sets intial previous guess so loop does not stop first try
prevGuess = np.zeros((1, aRows))
for i in range (0, aRows):
prevGuess[0,i] = 1000
guess2 = np.zeros((1, aRows))
limit = 0
aRows = int(A.shape[0])
aCols = int(A.shape[1])
while ((np.linalg.norm(guess - prevGuess) > tol) and limit < 100):
for j in range (0, aRows):
guess2[0,j] = b[j,0]
for i in range (0, aCols):
if (i != j):
guess2[0,j] = round((guess2[0,j] -(A[j,i]) * (guess[0,i])), 7)
guess2[0,j] = round((guess2[0,j] / A[j,j]), 7)
for i in range(0, aCols):
prevGuess[0,i] = guess[0, i]
for i in range(0, aCols-1):
guess[0, i] = round((guess2[0, i]), 7)
guess2 = np.zeros((1, aCols))
limit = limit + 1
#answers mod 2 to get real answers
#for i in range(0,aCols):
# guess[0,i] = guess[0,i]%2
#print ('\n')
#print(limit)
#print ('\n')
#print (guess)
#print ('\n')
我相信
range()
要求最大数包含在一个c整数范围内。如果您想绕过这个问题,可以使用itertools.count()
。它从0开始(或作为参数传递的数字),一直计数(或直到中断)。在示例:
文档:https://docs.python.org/2/library/itertools.html#itertools.count
相关问题 更多 >
编程相关推荐