Lesson 1 · Unit 02
Tensors
NumPy habits that carry over, and the three that do not
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?
import torch
t = torch.tensor([1.5, 2.5])
print(t.dtype)Correct answer
torch.float32
Why
PyTorch defaults to 32-bit floats: half the memory of float64, and what GPUs are built to crunch. Seven digits of precision is plenty for a model whose weights are noisy estimates anyway.
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.
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) # cpu11 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.