I met a problem when I use python to process my data, I want a three dimensional array, the first dimension is fixed at 5, the elements in second dimension are added dynamically, it`s type is array, the third dimension is how many number in the array, it is fixed at 4. code snippet is as follows:
three_d_array = [[]] * 5 # [[], [], [], [], []]
three_d_array[0] = [1,2,3,4] # [[1,2,3,4],[],[],[],[]]
three_d_array = [[]] * 5 # [[], [], [], [], []]
three_d_array[0].append([1,2,3,4]) # [[[1, 2, 3, 4]], [[1, 2, 3, 4]], [[1, 2, 3, 4]], [[1, 2, 3, 4]], [[1, 2, 3, 4]]]
I know *5 will generate one copy but five references, but why '=' can break this relationship? '=' must assign new memory address for this array, I wonder it assign five copies for three_d_array[1:5] or just one for three_d_array[0]?