appending a list in a loop
Dear all,
I have a problem with appending a list in loops. Here is just the relevant piece of my code: Z=6 M=4 er1 = np.zeros(Z) erg=[ ] for n in range(M):
for i in range(Z):
er1[i]=ergotropy(X[n][i],h[n])
print(er1)
erg.append(er1)
print(erg)
Each X[n][i] and h[n] is a matrix and the output of ergotropy is just a number which I store it in er1. Since M=4, at the end I have 4 different er1 as below:
[15.71957636 3.18431209 5.80234394 12.38512867 16.42427132 18.87485903] [38.94697417 6.72914646 6.30197238 14.81479759 20.68263418 24.4775205 ] [51.75894481 9.45566295 10.69628669 24.26926362 33.12816995 38.6311872 ] [52.0436407 8.28106587 14.85135832 33.94483248 46.84459702 55.11189418].
Now, when i'm going to append these 4 different arrays in erg as a list, the result is odd to me:
[array([52.0436407 , 8.28106587, 14.85135832, 33.94483248, 46.84459702, 55.11189418]), array([52.0436407 , 8.28106587, 14.85135832, 33.94483248, 46.84459702, 55.11189418]), array([52.0436407 , 8.28106587, 14.85135832, 33.94483248, 46.84459702, 55.11189418]), array([52.0436407 , 8.28106587, 14.85135832, 33.94483248, 46.84459702, 55.11189418])].
As you can see, it just append the last array of er1, 4 times. So what is the problem. I have tried different places to add my append order but it did not work. If anyone needs to look at my whole code, it is OK. Any tips is highly appreciated. Thank you very much.