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

Familiarizing yourself with tensors.

Learning Pytorch's tensor using it.

An short introduction about PyTorch and about the chosen functions.

  • argmax.
  • clamp.
  • copy_.
  • cuda.
  • item.
# Import torch and other required modules
import torch

Function 1 - torch.tensor.argmax.

So, your tensor is composed by numbers. Let's say you want to know where the larger number is, argmax is the way to go. It says to you where the max number is returning its index. Two parameteres are considered, dim and keepdim. The first is the dimension to consider and the second says if it the dimension will be retained. Let's see an example.

# Example 1 - working (change this)
t = torch.tensor([1, 2, 3, 4.]) # a 1-dimensional tensor composed by four numbers with indexes ranging from 0 to 3.
t.argmax()
tensor(3)