W3cubDocs

/PyTorch 2.9

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 type checking with mypy, and more explicit - so it’s recommended to use that instead of is_tensor.

Parameters

obj (object) – Object to test

Return type

TypeIs[Tensor]

Example:

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

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.is_tensor.html