I have written a pretty simple code to initialize a matrix, but I'm getting some very unexpected behaviour, this is the exact code that I run:
n = 2
b = [ ([0.0] * n) ] * n
c = [ ([0.0] * n) ] * n
a = [ [1.0, 2.0, 3.0], [2.0, 1.0, 3.0]]
....
print(c[0])
print(c[1])
for i in range(0, n):
b[i][0] = a[i][0] #this one is initialized as expected
c[0][i] = a[0][i] / b[0][0] # notice that c[1] isn't touched here in any way but when I print it out it is initialized to [1.0 1.0]
print("")
print(c[0])
print(c[1])
but these are the results I get from the print
statements:
[0.0, 0.0]
[0.0, 0.0]
[1.0, 1.0]
[1.0, 1.0]
(Only the first row should be initialized, not all of the elements)
I run Python 2.7.2
on Windows
.
Is there something I'm missing here?