[英]Efficient for loop for numpy arrays
Data_File I have a data frame of size [8192x29], i want to calculate the fft of each column but before that i need to reshape every column (8192 x 1) to (64 x 128). Data_File我有一个大小为 [8192x29] 的数据框,我想计算每一列的 fft,但在此之前我需要将每一列 (8192 x 1) 重塑为 (64 x 128)。 So for one column it goes like this所以对于一列它是这样的
data_1 = np.array(data_all.iloc[:,16])
data_1 = np.reshape(data_1,(64,128))
data_standarized = preprocessing.scale(data_1)
fft = fftpack.fft(data_standarized)
Now i have to apply the same for all the data and hence "for loop" for all the columns and calculates the fft separatel.现在我必须对所有数据应用相同的数据,因此对所有列应用“for循环”并计算fft分离。 I can't seem to think an efficient way to do that.我似乎想不出一种有效的方法来做到这一点。 my for loop is as follows我的for循环如下
data_k = np.zeros((64,3712))
for i in range(0,data_size[1]):
data_k[0:63, i:i+127]= data_all[:,i].reshape(64,128)
Then i need another for loop to get the 64 x 128 matrix one by one and apply fft.然后我需要另一个for循环来一个一个地获取64 x 128矩阵并应用fft。 In MATLAB if we have the structures we can do it with one for loop and every cell contains the output.在 MATLAB 中,如果我们有结构,我们可以使用一个 for 循环来完成,并且每个单元格都包含 output。 Can we do something like this in Python?我们可以在 Python 中做这样的事情吗?
fftpack.fft
will be applied to the last axis by default but you can specify any other axis as well: fftpack.fft
默认情况下将应用于最后一个轴,但您也可以指定任何其他轴:
data_new = data.reshape(64, 128, 29)
data_fft = fftpack.fft(data_new, axis=1)
Then you can reshape again if you like: data_fft.reshape(64, -1)
.然后,如果您愿意,可以再次整形: data_fft.reshape(64, -1)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.