본문 바로가기

Data Science/PyTorch

torch.Tensor / torch.tensor

 

https://pytorch.org/docs/stable/generated/torch.tensor.html

 

torch.tensor — PyTorch 1.12 documentation

Shortcuts

pytorch.org

 

 

코드 실행해보기

 

import torch


ex_list = [1, 2 ,3]
T_ex = torch.Tensor(ex_list)
t_ex = torch.tensor(ex_list)
ex_list[0] = 4
print(T_ex, t_ex)

print('-' * 40)

ex_tensor = torch.tensor(t_ex)  # t_ex = tensor([1, 2, 3])
T_ex = torch.Tensor(ex_tensor)
t_ex = torch.tensor(ex_tensor)
ex_tensor[0] = 4
print(T_ex, t_ex)

 

코드 실행 결과

 

 

위 코드의 실행 결과를 보면,

torch.Tensor / torch.tensor 둘의 차이를 대략적으로 알 수 있다.

 

 
 
 

 

UserWarning

 

코드 실행 결과와 함께 등장하는 "UserWarning"

위의 "UserWarning"과 관련된 내용

 

PyTorch 공식 문서에서 권장하는 tensor & Tensor 의 사용법이 적혀있다.

'Data Science > PyTorch' 카테고리의 다른 글

torch 공식 문서와 친해지기  (0) 2022.10.01
torch.gather / torch.scatter_  (0) 2022.09.27