I have a bit of code which I think is correct. However, it should return a vector of values but it returns a single cumulated value instead.
pExact = 0.8
pOvershoot = 0.1
pUndershoot = 0.1
def move(p, U):
q = []
for i in range(len(p)):
s = pExact * p[(i - U) % len(p)]
s = s + pOvershoot * p[(i - U - 1) % len(p)]
s = s + pUndershoot * p[(i - U + 1) % len(p)]
print i, s # check if calculations are corrects
q.append(s)
return q # should return a vector
p = [0, 1, 0, 0]
print move(p, 1) # prints only cumulated value
I try to understand why it prints only one value [0.10000000000000001] not a vector [0, 0.1, 0.8, 0.1] how I think it should.
It’s just an indentation problem. Your line
q.append(s)is at the same indentation level as the main part of the function, which means it only executes after the end of the for loop. Move it one level to the right, so it goes with the rest of the body of the loop, and it’ll be executed each time through the loop.