Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Assignment 1: All About torch.Tensor
Probability distributions in Tensors
In this notebook, I will be showing you how to build Tensors in PyTorch using different continuous and discrete probability distributions.
Note that this is different than using probability distributions to evaluate a tensor (e.g. using Bernoulli(torch.tensor[1])) and create distributions based on those tensors.
- torch.Tensor.cauchy_
- torch.Tensor.uniform_
- torch.Tensor.normal_
- torch.Tensor.bernoulli_
- torch.Tensor.geometric_
# Import torch and other required modules
import torch
Function 1 - torch.Tensor.cauchy_()
This function will fill a new tensor with numbers gathered from the Cauchy probability distribution. More information about this distribution can be found at https://mathworld.wolfram.com/CauchyDistribution.html
# Example 1 - working (change this)
t1= torch.Tensor(3,3).cauchy_(median = 0, sigma = 1, generator = None)
t1
tensor([[ -1.6426, 2.8174, -20.1251],
[ -0.9105, 0.0428, -1.4505],
[ -0.5068, 0.2860, -0.4843]])
This example is generated using the three default arguments for this function, taking in a median parameter, sigma being the half width at the half maximum point of the distribution, and a generator parameter