我必须通过对其应用两个滑动窗口来将 [17205, 21] 的 ndarray 重塑为 [17011, 96, 100, 21]。
In: arr
Out: [[ 8. 0. 0. -0. 0. 0. 8. 8. 0. 0. 0. 0. 8. 7. 6. 9. 9. 1.
1. 1. 2.]
[ 8. 0. 0. -0. 0. 0. 8. 8. 0. 0. 0. 0. 8. 7. 5. 9. 8. 2.
1. 1. 2.]
.
.
.
[ 8. 0. 0. -0. 0. 0. 8. 8. 0. 0. 0. 0. 8. 7. 5. 9. 8. 3.
1. 1. 2.]]
我的解决方案是两次对其应用滑动窗口。然后我两次应用以下方法:
def separate_multi(sequences, n_steps):
X = list()
for i in range(len(sequences)):
# find the end of this pattern
end_ix = i + n_steps
# check if we are beyond the dataset
if end_ix > len(sequences):
break
# gather input and output parts of the pattern
seq_x = sequences[i:end_ix, :]
X.append(seq_x)
return np.array(X)
给出 的形状,[17106, 100, 21]
然后再次使用n_step=96
,给出 的形状[17011, 96, 100, 21]
。
缺点:它将整个数据存储在内存中,这会产生错误:
MemoryError: Unable to allocate 24.3 GiB for an array with shape (17011, 96, 100, 20) and data type float64
一个可能的解决方案:
import tensorflow as tf
df = tf.data.Dataset.from_tensor_slices(df)
df = df.window(100, shift=1, stride=1, drop_remainder=True)
df = df.window(96, shift=1, stride=1, drop_remainder=True)
但是,它并没有给我想要的输出,因为“它会生成嵌套窗口的数据集”,正如这里所说的那样。
任何想法?谢谢