Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Tensors Operations
This Notebook is divided in 4 objectives.
- Creating Tensors in different ways with requires_grad property
- Comparing Tensor creation memory model
- Accessing Tensors
- Understanding WTH is requires_grad parameters
# Import torch and other required modules
import torch
import numpy as np
Objective-1 - Creating Tensors in different ways with requires_grad property
Calculating time to perform each type of tensors
Create all_one tensor with 2 internal matrixes where each matrix has 6 rows and 3 cols:
%time
all_one = torch.ones([2,6,3], dtype=torch.float64)
all_one
CPU times: user 3 µs, sys: 1e+03 ns, total: 4 µs
Wall time: 7.15 µs
tensor([[[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]],
[[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]]], dtype=torch.float64)