Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
My favorite pytorch functions
Pytorch is python library which extends the functionality of numpy to building regression models. A functions that I picked in order to share what I have learnt.
- tensor.stack
- tensor.randn
- tensor.abs
- tensor.add
- tensor.var
Before we begin, let's install and import PyTorch
# Import torch and other required modules
import torch
import numpy as np
Function 1 - torch.stack
Concatenates a sequence of tensors along a new dimension.
x=np.array([[3, 5],[7,8]])
print(type(x))
print(x.dtype)
<class 'numpy.ndarray'>
int64
z=torch.tensor([[4,5],[9,1]])
w=torch.tensor([[8,2],[0,2]])
print(z.shape)
torch.Size([2, 2])