I have a matrix-style array, that (hypothetically) looks like this:
mat = [[0,2,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
imat = mat
for i in xrange(4):
for j in xrange(4):
imat[j][i] = mat[i][j]
for i in xrange(4):
for j in xrange(4):
imat[j][i] = mat[i][j]
The code basically switches the row/column from "mat" to "imat".
The results:
mat:
[[0, 2, 0, 0], [2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
imat:
[[0, 2, 0, 0], [2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
Could anyone tell me why the array items are duplicating like this?
Also, if there is a more efficient way to do this operation, that would also be appreciated.