Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
PyTorch: Getting Started
Getting started with Python
PyTorch is a python-based scientific computing package targeted at two sets of audiences.
- A replacement for NumPy to use the power of GPUs
- A deep learning research platform that provides maximum flexibility and speed
Following 5 functions are to get started with Tensors in Python
- torch.randn
- torch.sort
- torch.linspace
- torch.reshape
- torch.transpose
# Import torch and other required modules
import torch
Function 1 - torch.randn
torch.randn(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution). The shape of the tensor is defined by the variable argument size.
# Example 1
x = torch.randn(4)
print('Initialized: ', x)
Initialized: tensor([-0.1617, 0.9721, 0.1014, 0.2569])
1-dimensional random values assigned in a tensor variable