answer_matrix=[["n.a"]*matrix_size]*matrix_size
my code
for c in a:
if answer_matrix[c[0]-1][c[1]-1]=="n.a":
answer_matrix[c[0]-1][c[1]-1]=c[2]
Now a
looks something like this
>>> a[0]
[1, 2, 1.3e-05, 6e-06, 0.0, 0.0, 0.0, 0.0, 0.0]
>>> a[1]
[1, 3, 0.000949, 0.000142, 0.0, 0.0, 1.8e-05, 5e-06, 0.00011]
>>> a[2]
[1, 4, 0.000417, 0.000126, 0.0, 0.0, 0.0, 0.0, 5.4e-05]
It is a list of list, first 2 entries are rows and columns (not using numpy yet)
My problem is that after running that for loop the answer_matrix is modified in places it shouldn't be.
For example in a there is no [1, 1, ...]
entry but I find the answer_matrix[0][0]
changed to 9e-06
.
When I try to get rid of the for loop and run the code with c=a[0]
for example, the code block works perfectly.
What exactly is happening?