【问题标题】:PyTorch TensorsPyTorch 张量
【发布时间】:2021-02-07 18:48:57
【问题描述】:

我是 PyTorch 的新手。谁能向我解释为什么我们应该在执行回归之前将数据帧转换为火炬张量? (如您所见,我已经拆分了数据集)。我还需要对这段代码进行解释:

x_train_tensor = torch.tensor(x_train.values.reshape(-1, 1), dtype = torch.float)
y_train_tensor = torch.tensor(y_train.values.reshape(-1, 1), dtype = torch.float)

x_test_tensor = torch.tensor(x_test.values.reshape(-1, 1), dtype = torch.float)
y_test_tensor = torch.tensor(y_test.values.reshape(-1, 1), dtype = torch.float)

谢谢!

【问题讨论】:

    标签: python pytorch tensor torch


    【解决方案1】:

    所有 Pytorch 操作都定义在 Tensors 上,它们本质上是多维矩阵。所以如果你想使用 Pytorch,你需要使用张量。

    【讨论】:

      【解决方案2】:

      pytorch 库中的所有操作或方法都仅在张量上执行。

      在上面的代码中,您首先使用 .reshape(-1,1) 将张量转换为列向量.....这是一种告诉 -1 是编译器自动决定值的位置,然后这些被转换为张量。

      【讨论】:

        猜你喜欢
        • 2021-10-11
        • 2022-10-17
        • 2020-03-28
        • 2023-04-04
        • 2018-10-27
        • 2019-11-26
        • 2021-01-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多