gpt4 book ai didi

python - reshape numpy为滞后值添加额外维度

转载 作者:行者123 更新时间:2023-12-01 03:51:23 24 4
gpt4 key购买 nike

我在为循环神经网络 reshape numpy 数组时遇到问题。我有一个看起来像这样的数组

     10 day       15 day   25 day
24 295.775 275.283333 281.16
25 296.000 275.483333 281.56
26 295.825 275.500000 281.75
27 295.425 275.350000 281.91
28 295.275 294.883333 282.04

当我将其转换为 numpy 数组时,其形状将是 (num_samples, 3 features)

但我需要做的是将其转换为 (num_samples, timesteps, 3 features)

数组看起来像

[ [ [295.775   275.283333   281.16]
[296.000 275.483333 281.56]
[295.825 275.500000 281.75]
[295.425 275.350000 281.91] ]
[ [296.000 275.483333 281.56]
[295.825 275.500000 281.75]
[295.425 275.350000 281.91]
[295.275 294.883333 282.04] ]

这里生成的 numpy 数组有(number_samples,4个时间步长,3个特征)

我一直在尝试为滞后变量添加新列并进行 reshape ,但无济于事

最佳答案

我认为你所追求的只是这样:

np.array([arr[i:i+4] for i range(len(arr)-4)]) 

关于python - reshape numpy为滞后值添加额外维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38201151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com