Bitpath

Lesson 1 · Unit 02

Tensors

NumPy habits that carry over, and the three that do not

13 exercisesabout 3 min

What you practise

  • Creating tensors, dtype and device, to and from NumPy, view/reshape, in-place operations and the trailing underscore

Try a question from this lesson

Pick one

NumPy would store these two numbers as float64. What does PyTorch print?

Python
import torch

t = torch.tensor([1.5, 2.5])
print(t.dtype)

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

An array with two extras

A tensor indexes, slices, broadcasts and reduces like a NumPy array. PyTorch says dim where NumPy says axis.

The extras: a tensor lives on a device (the CPU or a GPU), and it can record what was done to it so gradients can be computed later.

Python
import torch

t = torch.zeros(2, 3)
print(t.shape)       # torch.Size([2, 3])
print(t.sum(dim=1))  # tensor([0., 0.])
print(t.device)      # cpu

11 more exercises in the app

  • 3× type the answer
  • 4× multiple choice
  • 1× true or false
  • 1× fill the blanks
  • 1× order the lines
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy