Language/Python
[Python/Pytorch] TORCH.IS_TENSOR : Torch Tensor 여부 확인
밴나루
2022. 5. 17. 19:18
반응형
torch.is_tensor(obj )
obj가 PyTorch tensor라면 True를 return함
이 함수는 isinstance(obj, Tensor)을 수행하며, mypy를 통해 typechecking시에는 isinstance를 활용하는 편이 더 좋음
Parameters
obj (Object) - test할 객체(object)
Example
>>> import torch
>>> a = torch.tensor([1, 3, 5])
>>> torch.is_tensor(a)
True
>>> b = [1, 3, 5]
>>> torch.is_tensor(b)
False
Reference
https://pytorch.org/docs/stable/torch.html
torch — PyTorch 1.11.0 documentation
Shortcuts
pytorch.org
728x90