flâneur — a map of the web's best reading

torch.Tensor — PyTorch 2.12 documentation

docs.pytorch.org · 4,295 words · saved by 1 readers

A torch.Tensor is a multi-dimensional matrix containing elements of a single data type. Please see torch.dtype for more details about dtype support. A tensor can be constructed from a Python list or sequence using the torch.tensor() constructor: Warning torch.tensor() always copies data. If you have a Tensor data and just want to change its requires_grad flag, use requires_grad_() or detach() to avoid a copy. If you have a numpy array and want to avoid a copy, use torch.as_tensor(). A tensor of specific data type can be constructed by passing a torch.dtype and/or a torch.device to a constructor or tensor creation op: For more information about building Tensors, see Creation Ops The contents of a tensor can be accessed and modified using Python’s indexing and slicing notation: Use torch.Tensor.item() to get a Python number from a tensor containing a single value: For more information about indexing, see Indexing, Slicing, Joining, Mutating Ops A tensor can be created with requires_grad=

torch.Tensor # Created On: Dec 23, 2016 | Last Updated On: Jun 27, 2025 A torch.Tensor is a multi-dimensional matrix containing elements of a single data type. Please see torch.dtype for more details about dtype support. Initializing and basic operations # A tensor can be constructed from a Python list or sequence using the torch.tensor() constructor: >>> torch . tensor ([[ 1. , - 1. ], [ 1. , - 1. ]]) tensor([[ 1.0000, -1.0000], [ 1.0000, -1.0000]]) >>> torch . tensor ( np . array ([[ 1 , 2 , 3 ], [ 4 , 5 , 6 ]])) tensor([[ 1, 2, 3], [ 4, 5, 6]]) Warning torch.tensor() always copies data . If

Explore this link on the map →

related reading