A tensor operation is a PyTorch operation that acts on tensor data. Most operations are available both through the torch module and as methods on a tensor, with interchangeable behavior. section 3.7
Common tensor-operation families include:
- Creation operations construct tensors, while indexing, slicing, joining, and mutation operations change their shape, stride, or content. section 3.7
- Pointwise operations apply a function independently to each element; reduction operations compute aggregate values such as means, standard deviations, and norms. section 3.7
- Comparison, spectral, linear-algebra, random-sampling, serialization, and parallelism operations support numerical predicates, transformations, computation, generation, storage, and execution control. section 3.7
Calling the same operation two ways
Create a tensor with `a = torch.ones(3, 2)`. Transpose it either with `torch.transpose(a, 0, 1)` or with `a.transpose(0, 1)`; both produce a tensor whose shape is `(2, 3)`. section 3.7
Recognizing in-place operations
Methods ending in an underscore modify the input tensor instead of creating a new output. For example, `a.zero_()` replaces every element of a tensor with zero, while methods without the suffix leave the source unchanged. section 3.8.2


