Skip to content
← Learn PyTorch

Dtypes and Numerics

PyTorch

Choose tensor dtypes and reason about promotion, division, rounding and accumulated error. Compare floating-point results with suitable tolerances.

6 exercises

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. What dtype comes out Practice · Medium
  2. 2 Not solved yet. Counting with the wrong operator Practice · Easy
  3. 3 Not solved yet. Group integer indices with floor division Practice · Easy
  4. 4 Not solved yet. Where half precision stops Practice · Medium
  5. 5 Not solved yet. Compare floating-point tensors with tolerances Practice · Easy
  6. 6 Not solved yet. Convert dtype without unnecessary copies Practice · Easy

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

With float32 set as the default floating dtype, what dtype does y have?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

import torch

torch.set_default_dtype(torch.float32)
x = torch.ones(2, dtype=torch.int64)
y = x + 1.5
print(y.dtype)
print((x + torch.tensor([1.5], dtype=torch.float64)).dtype)
Question 1 of 4