Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
The 5 intersting functions
PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing, primarily developed by Facebook's AI Research lab. It is free and open-source software released under the Modified BSD license. We choose a function or two from each category.
- is_tensor
- as_tensor
- arange
- hstack
- randn
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 - torch.is_tensor
Returns True if obj is a PyTorch tensor.
# Example 1 - working
torch.is_tensor( torch.tensor([[1, 2], [3, 4.]]) )
True