I stumbled upon something that for the time being looks really weird to me. Maybe i have been looking at it for too long and too up-close, so i am counting on your fresh pair of eyes and, of course, expertise.
I have a list that i want to update, namely ply_info. The update consists of getting an element from the list (the one pointed by sign_reversal_index), duplicating it and adjusting the values of the original and copy-cat entries. This final bit is the weird one and takes place at the two last lines of code.
ply_info = [[0.3], [0.13], [0.13], [0.3], [0.13], [0.13], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3]]
t_ply = [0.3, 0.13, 0.13, 0.3, 0.13, 0.13, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]
height_list = [0]
for i in range(len(t_ply)):
height_list.append(height_list[i] + t_ply[i])
mid_plane_z = sum(t_ply) / 2
if mid_plane_z not in height_list:
print("...No ply boundary lies on mid plane.\n ...Splitting the one that crosses it.\n")
height_list.append(mid_plane_z)
height_list = sorted(height_list)
sign_reversal_index = height_list.index(mid_plane_z)
ply_to_duplicate = ply_info[sign_reversal_index-1]
ply_info.insert(sign_reversal_index-1, ply_to_duplicate)
ply_info[sign_reversal_index-1][0] = height_list[sign_reversal_index] - height_list[sign_reversal_index-1]
ply_info[sign_reversal_index][0] = height_list[sign_reversal_index+1] - height_list[sign_reversal_index]
I debugged the thing and it looks like the two entries are somehow linked and updating the one, updates the other too. Both values get updated twice, once in the second to last and once in the last line of code. Can anybody please explain why something like that is happening and how it relates to the creation of the copy? what would be the way to go about\around this?
the correct output would be:
[[0.3], [0.13], [0.13], [0.3], [0.13], [0.13], [0.3], [0.3], [0.3], [0.19], [0.11], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3], [0.3]]
notice the ...,[0.19], [0.11],...
Instead I am getting ...,[0.11], [0.11],...