EDITED WITH MINIMUM EXAMPLE
import numpy as np
T = np.random.rand(100) #defines a dummy T with size 100
corr = {}
for k in range(4):
corr[k] = np.corrcoef(T[50-k:100-k],T[50:100])
returns a dictionary corr
containing arrays. For instance :
corr[0]
> array([[1., 1.],
[1., 1.]])
If this is not applicable to your case, maybe the issue is in the corrcoef
, not the "appending" part!
EDITED WITH DICT
When you ask for corr_k
in your loop, python has no way of knowing that you want k
as a number. So it consider that your variable name is corr_k
and not corr_0
and so on as you would like. Which is hopeful, think about the nightmare it would be if python changed all k
character on its own! So, to specify a variable name which changes with the loop index, use a dictionary (as in this answer) and store the lists in it:
corr = {}
for k in range(4):
corr[k] = np.corrcoef ( T[(365-k):(730-k)] ,T[365:730] )
Then you will have your outputs with: corr[0]
, corr[1]
, corr[2]
, corr[3]
.
It is difficult to test your code as we do not have T
here, but as a first insight I see that for each step your are defining again corr_k=[]
, hence overwriting your list rather than appending it. Try:
corr_k= []
for k in range(4):
corr_k.append( np.corrcoef ( T[(365-k):(730-k)] ,T[365:730]) )