Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Jon Schwartz Assignment 1 - Tensor Operations
Tensor functions
For this assignment, I will be using the following functions:
# Import torch and other required modules
import torch
Function 1 - torch.tensor.flatten()
This method returns a new flattened tensor composed of all the original dimenions.
# Start with a non-flattened tensor
not_flat = torch.tensor([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
print(not_flat)
tensor([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 7, 8, 9],
[10, 11, 12]]])
Example 1 - working w/ default args
In this example, all dimensions are flattened into a single dimension (start_dim is implicitly 0)