简体   繁体   English

PyTorch 张量

[英]PyTorch Tensors

I am new to PyTorch.我是 PyTorch 的新手。 Can anyone explain to me why we are supposed to convert the data frame to a torch tensor, before performing Regression?谁能向我解释为什么我们应该在执行回归之前将数据帧转换为火炬张量? (I've split the dataset, as you can see). (如您所见,我已经拆分了数据集)。 And I also need an explanation to this piece of code:而且我还需要对这段代码进行解释:

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)

Thank you!谢谢!

All Pytorch operations are defined on Tensor s which are multi-dimensional matrixes in essence.所有 Pytorch 操作都定义在Tensor上, Tensor本质上是多维矩阵。 So you need to be using tensors if you want to use Pytorch.所以如果你想使用 Pytorch,你需要使用张量。

All operations or methods in pytorch libraries are performed on tensors only. pytorch 库中的所有操作或方法仅在张量上执行。

Here in the above code you are first converting your tensor to a column vector using .reshape(-1,1)..... it's a way of telling that -1 is where the compiler automatically decided the value and then these are converted to tensors.在上面的代码中,您首先使用 .reshape(-1,1.....到张量。

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

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