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

Updated 3 years ago

# Distributions function from college to Machine Learning

PyTorch is a deep learning framework and a scientific computing package, uses tensors that are optimized for deep learning using GPUs and CPUs.

Below are some common probability distribution and matrix functions, we studied in our college that can be used in machine learning.

- bernoulli()
- uniform_()
- normal()
- poisson()
- exponential_()

let's install and import PyTorch

```
# 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 and other required modules
import torch
```

### bernoulli()

Bernoulli is a probability distribution used to predict success (p) and failure (1-p) rate from a discrete random variable.

```
# Example 1
p = torch.tensor([0.6759], dtype=float)
torch.bernoulli(p)
```

`tensor([1.], dtype=torch.float64)`