Updated 3 years ago
Wonders of 5 Pytorch tensors
Pytorch is a library for processing tensors. A Tensor is a number, vector , matrix or any n-dimentional array.
- function 1 : zeros_like
- function 2 : eye
- function 3 : conj
- function 4 : chunk
- function 5 : narrow
Before we begin, 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
Function 1 - zeros_like
zeros_like tensor returns a tensor filled with '0', with the same size as input.
# Example 1 - working
x = torch.tensor([[1, 2], [3, 4.]])
x
tensor([[1., 2.],
[3., 4.]])