I create a matrix with 4 lines and 5 columns filled with zeros. Then i put some values into the first line (line 0) and want to calculate values for the second line (line 1) with a function. My code is:
x = [0,1,2,1,0]
u=[[0]*(len(x))]*(4)
u[0]=x
for n in range(0,1):
print u
for j in range(1,4):
u[n+1][j]=u[n][j]-(u[n][j+1]-u[n][j-1])
print 'Value %.f at position %.f %.f' %(u[n+1][j],n+1,j)
print u
But the results of prints is:
[[0, 1, 2, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
Value -1 at position 1 1
Value 2 at position 1 2
Value 3 at position 1 3
[[0, 1, 2, 1, 0], [0, -1, 2, 3, 0], [0, -1, 2, 3, 0], [0, -1, 2, 3, 0]]
I don't understand why the program calculates values for the line 1 and columns 1, 2 and 3 but after the loop lines 2 and 3 are also with values. I expect the results of prints was:
[[0, 1, 2, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
Value -1 at position 1 1
Value 2 at position 1 2
Value 3 at position 1 3
[[0, 1, 2, 1, 0], [0, -1, 2, 3, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]