Learn practical skills, build real-world projects, and advance your career

Torch Functions

some useftorch function

An short introduction about PyTorch and about the chosen functions.

  • function 1
  • function 2
  • function 3
  • function 4
  • function 5
# Import torch and other required modules
import torch

Function 1 - torch.mul

multiply the tensor with scalar or with another tensor

A = torch.randn(3,4)
print(A)
torch.mul(A, 100)
tensor([[-1.2924, 0.6837, 1.0688, 0.8973], [ 1.0213, 0.5083, -0.2543, 1.7965], [-1.4648, 1.2651, -0.0638, -0.1726]])
tensor([[-129.2389,   68.3713,  106.8801,   89.7258],
        [ 102.1286,   50.8312,  -25.4315,  179.6485],
        [-146.4752,  126.5119,   -6.3806,  -17.2602]])

The each element of tensor A is multiplied by 100(Scalar)