当我运行脚本时,我收到了递归错误。我不知道如何去做,因为我的节目在不到一个小时的时间到期。如果有人能给我一些很棒的见解!这是一个两部分的脚本。
我的代码
import math
import random
from random import randrange, uniform
def add(u, v):
sum1 = [x + y for x, y in zip(u, v)]
return sum1
def negate(u):
myng = [x - 2*y for x, y in zip(u, u)]
return myng
def sub(u,v):
d = [x - y for x, y in zip(u, v)]
return d
def scalarMult(c, u):
m = [(x+y-y)*c for x, y in zip(u,u)]
return m
def zip(u,v):
mt = [x * y for x, y in zip(u, v)]
return mt
def dot(u, v):
l = zp(u,v)
a = sum(l)
return a
def length(u):
d = dot(u,u)
x = math.sqrt(d)
return x
def unit(v):
l = length(v)
m = [(x+y-y)/l for x,y in zip(v,v)]
return m
def randVector(n, a, b):
l = [] * n
i = 0
while(i<n):
l.append(random.uniform(a,b))
i=i+1
return l
#------------------------------------------------------------------------------
# VectorTest.py
#------------------------------------------------------------------------------
import Vector
A = [-3, -4, 7]
B = [6, -2, 2]
print(A)
print(B)
print(Vector.add(A,B))
print(Vector.negate(B))
print(Vector.sub(A,B))
print(Vector.scalarMult(2.5,A))
print(Vector.scalarMult(-3.5,B))
print(Vector.zip(A,B))
print(Vector.dot(A,B))
print(Vector.length(A))
print(Vector.length(B))
print(Vector.unit(A))
print(Vector.unit(B))
print(Vector.angle(A,B))
C = Vector.randVector(3,-10,10)
print(Vector.sub(C,C))
答案 0 :(得分:1)
您的zip
函数无限调用自身,生成无限递归。
def zip(u, v):
mt = [x * y for x, y in zip(u, v)]
return mt
当你调用它时,它必须调用自己来获取它的值。当它以这种方式调用时,它会一次又一次地调用自己,永远不会完成。