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

[Edit] Python (Pytorch): .cat() #6485

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mamtawardhani
Copy link
Collaborator

Description

[[Edit] Python (Pytorch): .cat()

Issue Solved

Closes #6472

Type of Change

  • Editing an existing entry (fixing a typo, bug, issues, etc)

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@mamtawardhani mamtawardhani added enhancement New feature or request status: under review Issue or PR is currently being reviewed pytorch PyTorch labels Apr 5, 2025

<details>
<summary>2. Can I concatenate tensors of different data types or devices?</summary>
<p>No. All tensors must have the same data type and must be on the same device (e.g., all on CPU or all on GPU). Mismatches will raise an error.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add backlink to CPU and GPU

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have one for GPU, added 1cpu blog link (It has better content than docs)


A new tensor resulting from concatenating the input tensors along the specified dimension.

## Example 1: Concatenating tensors along the first dimension
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line -"The output shows the two tensors and the concatenated tensor along the first dimension:" is repetitive in all three examples. Consider rewriting it. We are saying the same thing in the example heading, then description of example and output description.

@@ -115,9 +115,9 @@ tensor([[ 1, 2, 3, 7, 8, 9],
[ 4, 5, 6, 10, 11, 12]])
```

## Example 3: Concatenating tensors along the third dimension
## Example 3: Appending Tensors on the Depth Dimension
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the earlier name


The example below showcases concatenating tensors along the third dimension using the `.cat()` function:
This example illustrates how to append tensors along the third dimension (axis 2), effectively stacking them in depth using the `.cat()` method:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This example illustrates how to append tensors along the third dimension (axis 2), effectively stacking them in depth using the `.cat()` method:
This example shows how to append tensors along the third dimension (axis 2), effectively stacking them in depth using the `.cat()` method:

@@ -75,9 +75,9 @@ tensor([[ 1, 2, 3],
[10, 11, 12]])
```

## Example 2: Concatenating tensors along the second dimension
## Example 2: Stacking Tensors Across the Second Axis
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the earlier name

@@ -33,9 +33,9 @@ torch.cat(tensors, dim=0, out=None)

A new tensor resulting from concatenating the input tensors along the specified dimension.

## Example 1: Concatenating tensors along the first dimension
## Example 1: Merging Tensors Along Dimension 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the earlier name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Edit] Python (Pytorch): .cat()
2 participants