很抱歉问这个问题,如果已经问过了,但是在我的例子中,我有一个3000000x50大小的特殊矩阵,我想把它拆分成30000x50大小的300个矩阵。我试过了但没用
>>>import numpy as np
>>>data=np.random.randn(3000000,50)
>>>D=np.matrix.conjugate(data)
>>>ts=50
>>>ts=int(ts) #number of time series that we have from our data
>>>lw=1e4
>>>lw=int(lw) #length of each window
>>>l=len(data)/lw #l is number of windows
>>>l=np.floor(l)
>>>l=int(l)
#Dc is used to seperate each time series in l windows
>>>Dc=np.zeros((l,lw,ts))
>>>for i in range(l):
Dc[i][0:lw-1][0:ts-1]=D[(lw)*(i):(lw*(i+1))-1][0:ts-1]
最佳答案
如果您的初始数组已正确排序,并且希望将数组拆分为300个矩阵“框”,则只需对marix进行以下重新定义
import numpy as np
data = np.random.randn(3000000,50)
newData = data.reshape(300,10000,50) # This is as [300,10000,50] array
print newData[0,...] # Show the first matrix, 1 of 300