Python 创建和操作三维阵列
我(非常)不熟悉python,以前是Matlab用户 我尝试创建代码,将时间序列加载到矩阵的行中[serie1、2、3等],然后将这些时间序列处理成循环(请参见下面的代码)。 我的问题有三个方面(下面有3个循环): 1-如何创建循环以逐个填充数组的行。 2-用我根据这些时间序列(相关系数)计算的东西填充一个3d数组 3-计算每个时间段下三角矩阵的平均相关性 我做错了什么 非常感谢你的帮助Python 创建和操作三维阵列,python,multidimensional-array,numpy,Python,Multidimensional Array,Numpy,我(非常)不熟悉python,以前是Matlab用户 我尝试创建代码,将时间序列加载到矩阵的行中[serie1、2、3等],然后将这些时间序列处理成循环(请参见下面的代码)。 我的问题有三个方面(下面有3个循环): 1-如何创建循环以逐个填充数组的行。 2-用我根据这些时间序列(相关系数)计算的东西填充一个3d数组 3-计算每个时间段下三角矩阵的平均相关性 我做错了什么 非常感谢你的帮助 i=0 while i<length(fx_tech): for f in fx_tec
i=0
while i<length(fx_tech):
for f in fx_tech:
time_series[:,i]= (LoadSeries(f[2],'7','fx','0',(ts.now('Y')-20).asfreq('B'),ts.now('B')-1,'0','0','B'))
i=1+i
#i want to populate a matrix with all series, fx_tech is a list of series i have
#to feed through the "loadseries" command. I know the first set of loops is wrong.
#then loop over each series pair and populate the matrix "corr"
corr = zeros((len(time_series)-1,len(fx_tech),len(fx_tech))) #allocate matrix
i=0
j=0
while i < len(fx_tech):
while j < len(fx_tech):
corr[:,i,j] = gencorrelation(time_series[:,i],time_series[:,j],lambda1)
j=1+j
i=1+i
#finally calculate the average of the elements below the diagonal for each time period.
mean_fx = []
i=0
while i < len(time_series)-1:
diag[:,:] = corr[i,:,:]-eye(len(fx_tech))
mean_fx.append = sum(diag)/((len(fx_tech)**2)/2-len(fx_tech))
i=1+i
i=0
为了让人们更好地回答您的问题,您可能需要添加一些示例输出以及您希望看到的输出的示例。