Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] PyTorch Tensor Operations: .is_tensor() #6118

Merged
merged 7 commits into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
Title: '.is_tensor()'
Description: 'Checks if the given object is a PyTorch tensor.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Arrays'
- 'Data Structures'
- 'Deep Learning'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/computer-science'
---

In PyTorch, the **`.is_tensor()`** function checks if the given object is a PyTorch [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). It returns `True` if the object is a tensor; otherwise, it returns `False`. This function is part of the `torch` module.

## Syntax

```pseudo
torch.is_tensor(obj)
```

- `obj`: The object to check whether it is a PyTorch tensor.

## Example

The following example demonstrates the usage of the `.is_tensor()` function:

```py
import torch

# Define objects
tensor_obj = torch.tensor([11, 22, 33, 44, 55]) # Tensor object
list_obj = [11, 22, 33, 44, 55] # Non-tensor object

# Check if the objects are PyTorch tensors
print(torch.is_tensor(tensor_obj)) # True
print(torch.is_tensor(list_obj)) # False
```

The above code produces the following output:

```shell
True
PragatiVerma18 marked this conversation as resolved.
Show resolved Hide resolved
False
```