Shortcuts

torch.is_tensor

torch.is_tensor(obj, /)[source]

Returns True if obj is a PyTorch tensor.

Note that this function is simply doing isinstance(obj, Tensor). Using that isinstance check is better for typechecking with mypy, and more explicit - so it’s recommended to use that instead of is_tensor.

Parameters

obj (object) – Object to test

Return type

typing_extensions.TypeIs[Tensor]

Example:

>>> x = torch.tensor([1, 2, 3])
>>> torch.is_tensor(x)
True

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources