I am writing a program that dose many math computations that eventually make a list of points to plot. I does so over several iterations and gets one point per iteration, and then uses the new point for the next iteration in the code. The list conditions_old
holds the values from the last iteration. The list conditions_new
are the new points that are found after an iteration is finished. At the end of the code, the lists are set equal to each other: conditions_old = conditions_new
. This is the only time conditions_old
is assigned a value except for the initial conditions that are used to start the calculations. With all that said, here is the problem I'm having:
conditions_old = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
kCompute = conditions_old[:]
for i in range(3):
for j in range(3):
print("conditions_old BEFORE: ", conditions_old[i][j])
kCompute[i][j] = (conditions_old[i][j] + (1/4)) # This is where things get fishy.
print("conditions_old AFTER: ", conditions_old[i][j])
print("kCompute: ", kCompute[i][j])
This is a small portion of my code. What happens is that the list conditions_old
will acquire the values of kCompute
once that calculation has been made. My question is this; why is conditions_old
acquiring the the new value of kCompute
? Also, how do you fix this problem?
I've seen python do some odd things before, but this is something I never expected to run into.
I'm currently using python 3.4 on Yosemite