PyTorch Tensor Flashcards
(66 cards)
What is PyTorch?
PyTorch is an open-source machine learning framework based on the Torch library
What is the main difference between PyTorch and NumPy?
PyTorch provides similar array/tensor operations as NumPy but also supports GPU acceleration and building/training neural networks.
What does PyTorch’s dynamic computational graph mean?
It means the computation graph is created on the fly as operations are executed
List the typical PyTorch workflow steps.
1) Prepare data; 2) Build model (e.g.
What is torch?
The core Python module of the PyTorch library
How do you import core PyTorch components in Python?
import torch as t; from torch import nn; import matplotlib.pyplot as plt
What does t.__version__ do?
Prints the version of the installed PyTorch library.
What does t.empty(5
3) do?
What is the risk of using t.empty()?
Values are arbitrary (may be NaN or random) because memory is allocated but not initialized.
How to create an empty 5x5 tensor?
t.empty(5
How do you create a tensor from a scalar?
t.tensor(10)
How do you check a tensor’s dimension?
tensor.ndim
How do you create a tensor from a list of floats?
t.tensor([5.5
How do you create a 2D tensor from nested lists?
t.tensor([[7
Given Q2 = [[2
3
How do you create a random tensor of shape 5x3?
t.rand(5
How do you create a random tensor from normal distribution?
t.randn(5
How do you create a tensor with the same shape as another but with random values?
t.randn_like(existing_tensor)
What does a.size() or a.shape return?
Returns the shape of tensor a as a tuple
How do you create a random RGB image tensor?
random_image_size = t.rand(size=(3
How to print shape
dimension
How do you convert a tensor to a PIL image?
Use torchvision.transforms.ToPILImage() and call it on the tensor.
What is the difference between torch.range and torch.arange?
torch.arange is preferred; torch.range is deprecated and differs from Python’s range; arange excludes the stop value.