This is an uncluttered version of this question. Since I changed so much I made a new question
I am trying to take certain values from a longer array solution
and put them into a smaller array, within an object. This code is supposed to take the first half of the solution
array and put it into x_hist
within m1
, and the second half of the solution
array and put it into x_hist
within m2
. Instead it appears to take all of the solution
array and put it into x_hist
for both objects. Anyone know why this may be the case? Have I accidentally vectorized the code?
class Mass:
x_hist = []
m1 = Mass()
m2 = Mass()
ms = [m1,m2]
solution = [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(len(ms)):
for k in range(int(len(sol)/len(ms))):
ms[i].x_hist.append(solution[k+8*i])
print(m1.x_hist)
print(m2.x_hist)
The output is:
[1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0]
[1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0]
I am trying to get an output of:
[1, 2, 3, 4, 5, 6, 7, 8]
[0, 0, 0, 0, 0, 0, 0, 0]