파이토치에서 텐서는 넘파이의 ndarray를 조작하는 것과 유사하게 동작한다. 텐서 생성 및 변환 import torch torch.tensor([[1., -1], [1.,-1]]) # 2차원 텐서 생성 torch.tensor([[1., -1], [1.,-1]], device = "cuda:0") # GPU에 텐서 생성 torch.tensor([[1., -1], [1.,-1]], dtype=torch.int32) # dtype을 이용해 텐서 생성 실행 결과 tensor([[ 1., -1.], [ 1., -1.]]) tensor([[ 1., -1.], [ 1., -1.]], device='cuda:0') tensor([[ 1, -1], [ 1, -1]], dtype=torch.int32) 첫번째는 그냥 텐..
[PyTorch] 텐서 기초 문법
파이토치에서 텐서는 넘파이의 ndarray를 조작하는 것과 유사하게 동작한다. 텐서 생성 및 변환 import torch torch.tensor([[1., -1], [1.,-1]]) # 2차원 텐서 생성 torch.tensor([[1., -1], [1.,-1]], device = "cuda:0") # GPU에 텐서 생성 torch.tensor([[1., -1], [1.,-1]], dtype=torch.int32) # dtype을 이용해 텐서 생성 실행 결과 tensor([[ 1., -1.], [ 1., -1.]]) tensor([[ 1., -1.], [ 1., -1.]], device='cuda:0') tensor([[ 1, -1], [ 1, -1]], dtype=torch.int32) 첫번째는 그냥 텐..
2023.02.14