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

PyTorch Tensor Function Examples

Sample introductory approaches for ML

PyTorch is a popular platform used in Machine Learning. The functions described belove are only a sample of the many tools that can be used when creating models. It is always satisfactory to see familiar concepts presented in many concepts.

  • torch.sigmoid
  • torch.argmax
  • torch.t
  • torch.transpose
  • torch.mean
# Import torch and other required modules
import torch

Function 1 - torch.sigmoid

Besides regression, logistic regression is the next major approach used when considering an output that would be binary. Classification is the more widely-used and less scary term associated.

The Sigmoid function would be used in calculations such as cost functions.

The equation is: output = 1/1+e^-input

# Example 1 - working (change this)
#torch.tensor([[1, 2], [3, 4.]])
a = torch.randn(6)
a
tensor([ 0.3004,  0.5729,  0.5238, -0.8440, -1.2629,  1.3535])
torch.sigmoid(a)
tensor([0.5745, 0.6394, 0.6280, 0.3007, 0.2205, 0.7947])