简体   繁体   English

将 2D 数组更改为 3D 数组

[英]Changing a 2D array into a 3D array

I have an array that has 8450 rows and 16 columns.我有一个有 8450 行和 16 列的数组。 I want to feed these data points into an RNN with each 50 points being an entry.我想将这些数据点输入到 RNN 中,每 50 个点作为一个条目。 So 0-49 is z=0, and 1-50 is z=1 and so forth.所以 0-49 是 z=0,1-50 是 z=1 等等。 The columns need to remain unchanged so that I can still have the same data in each z axis entry.列需要保持不变,以便我仍然可以在每个 z 轴条目中拥有相同的数据。 So basically I am taking every chunk of 50 points and moving it into a third axis.所以基本上我把每块 50 点都移到第三个轴上。 Is there simple way to do this python?有没有简单的方法来做这个python? I tried the reshape but I may not have been doing it correctly.我尝试了重塑,但我可能做得不对。 Currently the data is in a pandas dataframe.目前,数据位于熊猫数据框中。

points = 50
for i in range(len(data_prepped_dataframe)-points):
     x_data = data_prepped_dataframe.iloc[i:i+points,:]

So far I have this but all this does is give me the last 50 points in the data set.到目前为止,我有这个,但所有这些都是给我数据集中的最后 50 个点。 I tried adding indexes to the x_data term but that threw an error我尝试向 x_data 项添加索引,但这引发了错误

I tried我试过

x_data[:,:,i] = data_prepped_dataframe.iloc[i:i+points,:]

but the error said x_data wasn't defined.但错误说 x_data 未定义。

If you change the dataframe to an array using np.array() and then add .copy() at the end this will output the 3D array.如果您使用 np.array() 将数据帧更改为数组,然后在末尾添加 .copy() 这将输出 3D 数组。 Specifically in this case a (8400 x 50 x 16) array在这种情况下,特别是 (8400 x 50 x 16) 阵列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM