Code
torch.tensor()
The torch.tensor() function in PyTorch constructs a tensor from data such as a Python list or a NumPy array. When preparing datasets for neural networks, this function is used to load numerical features and target labels into PyTorch's native multidimensional array format.
0
1
Updated 2026-05-01
Tags
D2L
Dive into Deep Learning @ D2L