Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
5 Amazing PyTorch Functions
Table of Contents
- torch.randn()
- torch.sort()
- torch.det()
- torch.repeat()
- torch.matrix_power()
# Import torch and other required modules
import torch
Function 1 - torch.randn()
This function creates a pytorch tensor of the given shape filled with random values from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).
# Example 1 - Creating a random vector
a = torch.randn(2)
a
tensor([-0.7021, 0.7412])
In this example, a tensor with shape 2 was created (containing random numbers)