Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Probability distributions
A quick understanding on how to use the torch distributions
- torch.bernoulli()
- torch.rand()
- torch.poisson()
- torch.normal()
- torch.multinomial()
# Uncomment and run the appropriate command for your operating system, if required
# Linux / Binder
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# Windows
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# MacOS
# !pip install numpy torch torchvision torchaudio
import torch
Function 1 - torch.bernoulli
Draws binary random numbers (0 or 1) from a Bernoulli distribution.
# Example 1
a = torch.distributions.Bernoulli(torch.tensor([0.41]))
a.sample()
tensor([0.])