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

First assignment

Learning how to use PyTorch

An short introduction about PyTorch and about the chosen functions.

  • torch.tensor
  • torch.nn
  • torch.onnx
  • torch.random
  • torch.storage
# Import torch and other required modules
import torch

Function 1 - torch.tensor

The "tensor" function is the most basic and fundamental one from the whole PyTorch. You can find its documentation here: https://pytorch.org/docs/stable/tensors.html

# Example 1 - Define a 2 by 2 matrix
torch.tensor([[1, 2], [3, 4.]])
tensor([[1., 2.],
        [3., 4.]])

As you can see, the Tensor function is useful to define tensors (n-dimentional matrixes).