I try to make a table where I calculate an expectation value and vary 3 different parameters i,j,k (and also average over 20 values each). The expected result is a (4,6,5) table/list structure that has 120 different entries depending on the parameters indexed by i,j,k. The final step where I average the values does not work. The actual result is that there are only 5 different entries that appear 24 times each. I recreated a similar simplified problem where the averaging is not necessary as the values for a certain (i,j,k) do not differ, but where zt is the input list with different entries (i times j times k), and z is the output list that should show all possible combinations of (i times j times k), but it does not. It appears that only the last (i,j) is taken for each k. The problem is obviously in the loop, but I have no clue why it does not work as it should. Below is the code and the result z.
import numpy as np
zt = np.zeros([4,6,5,20])
z = [[['']*5]*6]*4
for i in range(4):
for j in range(6):
for k in range(5):
for l in range(20):
zt[i][j][k][l] = i*j*k
E0mean = np.sum(zt[i][j][k])/20 #Mean of the n calculations
E0dev = max(zt[i][j][k])-min(zt[i][j][k])/2 #uncertaincy
z[i][j][k] = str(round(E0mean,5))+u"\u00B1"+str(round(E0dev,5)) #results: mean +- uncertainty
z
Output:
[[['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0']],
[['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0']],
[['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0']],
[['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0'],
['0.0±0.0', '15.0±0.0', '30.0±0.0', '45.0±0.0', '60.0±0.0']]]