Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Five Interesting Pytorch Functions
The torch package which seats on pytorch was created by the Facebook's AI research laboratory. The package contains multi-dimensional tensors and mathematical operations.An interesting fact about pytorch is that it has a CUDA counterpart that enables you to run your tensor computations on an NVIDIA GPU with compute capability >= 3.0
List of functions in view
- chunk
- transpose
- rand
- add
- inverse
Before we begin, let's install and import PyTorch
First, let's import the torch library
import torch
Next we create a tensor, in this case, i created a 7 by 5 tensor, that is 7 rows and 5 columns, it's a 2 dimensional tensor.
t1 = torch.tensor([[1,2,3,4,5],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[3,4,5,6,7],[1,1,1,1,1]])
t1
tensor([[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8],
[3, 4, 5, 6, 7],
[1, 1, 1, 1, 1]])