【问题标题】:I do not understand this slicing or reshape in numpy我不明白 numpy 中的这种切片或重塑
【发布时间】:2019-08-25 19:11:56
【问题描述】:

完整代码:https://colab.research.google.com/drive/1W6k_nq890Fj5StsUtK4Hs1vorUgu0moA

它如何从 (3621, 30, 1) 重塑或切片 到 (1150,)。我不明白。 感谢您的帮助!

print(len(series[..., np.newaxis]))
print((tf.expand_dims(series[..., np.newaxis], axis=-1).shape))
rnn_forecast = model_forecast(model, series[..., np.newaxis], window_size)
print("before reshape: "+str(rnn_forecast.shape))
rnn_forecast = rnn_forecast[split_time - window_size:-1, -1, 0]
print("After reshape: "+str(rnn_forecast.shape))

output:
3650
(3650, 1, 1)
before reshape: (3591, 60, 1)
After reshape: (1150,)

【问题讨论】:

  • np.newaxistf.exapnd_dims 各自添加一个维度,从而形成 (3650,1,1) 形状。 rnn_forecast[split_time - window_size:-1, -1, 0] 从 (3591, 69, 1)` 数组中选择项目 - 第一个维度上的切片,其他 2 上的标量索引。

标签: numpy tensorflow


【解决方案1】:

此代码不执行整形。 两个打印语句之间的 getitem 调用为三个轴中的每一个选择一个切片 对于轴 0,切片为 split_time-window_size -1:-1,因此在索引 3648 处结束 对于轴 1,切片是单个索引 -1,在此示例中相当于索引 29 对于轴 2,切片是单个索引 0

结果是一个只有一个轴的数组。

简而言之,reshape 在这个例子中没有任何作用

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2020-12-05
    • 2020-04-16
    • 2022-12-06
    • 2018-09-02
    • 2010-10-04
    • 1970-01-01
    • 2020-04-04
    相关资源
    最近更新 更多