Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
5 Pytorch functions worth checking out.
Function List
PyTorch is a popular open source machine learning library based on the Torch library, primarily developed by Facebook's AI Research lab
- torch.from_numpy()
- torch.rand()
- torch.zeros()
- torch.squeeze()
- torch.ones()
# Import torch and other required modules
import torch
import numpy as np
Function 1 - torch.from_numpy()
This function creates a Tensor from a numpy.ndarray.
# Example 1 - working (conversion to tensor)
a = np.array([1, 2, 3])
t = torch.from_numpy(a)
t
tensor([1, 2, 3])
The numpy array is converted to a tensor.