머신러닝 알고리즘을 구현·실행하기 위한 딥러닝 라이브러리이다.
파이썬에서 import torch 해서 사용할 수 있다.
tensor는 PyTorch의 기본 데이터 구조이다.
a = torch.tensor(28.4)
a = torch.tensor([72, 9.3, 34, 120, 15.7])
a = torch.tensor([[72, 9.3, 34, 120, 15.7],
[3.9, 560, 146, 9, 13],
[0.62, 280, 24, 33, 14.7]])
a = torch.tensor([[[255, 0, 0],
[0, 255, 0]],
[[0, 0, 255],
[255, 255, 0]]])
tensor를 쌓을 때에는 stack 메서드를 이용하면 된다.
tensor_a = torch.tensor([[[255, 0, 0],
[0, 255, 0]],
[[0, 0, 255],
[255, 255, 0]]])
tensor_b = torch.tensor([[[255, 0, 0],
[0, 255, 0]],
[[0, 0, 255],
[255, 255, 0]]])
tensor_c = torch.tensor([[[255, 0, 0],
[0, 255, 0]],
[[0, 0, 255],
[255, 255, 0]]])
# dimension 2 를 기준으로 stack
tensor3d = torch.stack((tensor_a, tensor_b, tensor_c), dim=2)
★ 3-D tensor의 구조
m x n x l 의 크기를 가지는데, m개의 n x l 행렬이 있는 것으로 해석할 수 있다.
m이 dim = 0, n이 dim = 1, l이 dim = 2