Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Assignment 1 of Deep Learning with PyTorch: Zero to GANs
pyTorch Tensor
Here is my five interesting functions that related to PyTorch tensors.
- torch.arange()
- torch.Tensor.view()
- torch.reshape()
- torch.det()
- torch.matmul()
# Import torch and other required modules
import torch
Function 1 - torch.arange()
torch.arange(start=0, end, step=1, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
This function return the 1-D Tensor. Typically this tensor contain linear squence of numbers when we define the start, end and step that we need to arrange. The default values for start and step are 0 and 1.
# Example 1 - working
torch.arange(10)
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Above example we pass 10 a as argument. So the function will like arange(start=0,end=10, step=1)
. Therefore it return the 1-D tensor that has a linear sequnce of numbers in between 0 to 9. The start number is included and the end number is excluded.