Introduction to Deep Learning with PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$
$$
$$
$$
$$
$$
import torch
my_list = [[1, 2, 3], [4, 5, 6]] tensor = torch.tensor(my_list) print(tensor)
tensor([[1, 2, 3],
[4, 5, 6]])
my_list = [[1, 2, 3], [4, 5, 6]]
tensor = torch.tensor(my_list)
print(tensor.shape)
torch.Size([2, 3])
print(tensor.dtype)
torch.int64
a = torch.tensor([[1, 1],
[2, 2]])
b = torch.tensor([[2, 2],
[3, 3]])
print(a + b)
tensor([[3, 3],
[5, 5]])
a = torch.tensor([[1, 1],
[2, 2]])
c = torch.tensor([[2, 2, 4],
[3, 3, 5]])
print(a + c)
RuntimeError: The size of tensor a
(2) must match the size of tensor b (3)
at non-singleton dimension 1
a = torch.tensor([[1, 1],
[2, 2]])
b = torch.tensor([[2, 2],
[3, 3]])
print(a * b)
tensor([[2, 2],
[6, 6]])
$$
$$
Introduction to Deep Learning with PyTorch