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 .hstack() #5528

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

Conversation

clonymontana
Copy link

Description

-Added the .hstack() function term under PyTorch
-Closes Issues #5468

Issue Solved

Type of Change

  • Adding a new entry

Checklist

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

clonymontana and others added 2 commits October 18, 2024 23:11
PyTorch Tensors .hstack()
@CLAassistant
Copy link

CLAassistant commented Oct 19, 2024

CLA assistant check
All committers have signed the CLA.

@mamtawardhani mamtawardhani self-assigned this Oct 19, 2024
@mamtawardhani mamtawardhani added new entry New entry or entries hacktoberfest-accepted Indicates the PR was approved, merged, and pertains to Hacktoberfest status: under review Issue or PR is currently being reviewed pytorch PyTorch labels Oct 19, 2024
fixed meta data table
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

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

Hey @clonymontana thank you for contributing to Codecademy Docs 😄

I've suggested some changes, could you please review and modify those at your earliest convenience? Thank you! 🚀

Comment on lines 1 to 15
---
Title: '.hstack()'
Description: 'The `.hastack(tensors)` is a function used to concetante two or more tensors along horizontal axis.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Data Types'
- 'Deep Learning'
- 'Functions'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/data-science'
---
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
---
Title: '.hstack()'
Description: 'The `.hastack(tensors)` is a function used to concetante two or more tensors along horizontal axis.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Data Types'
- 'Deep Learning'
- 'Functions'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/data-science'
---
---
Title: '.hstack()'
Description: 'Concatenates two or more tensors along the horizontal axis (column-wise)'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Data Types'
- 'Deep Learning'
- 'Functions'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/data-science'
---

Copy link
Collaborator

Choose a reason for hiding this comment

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

description should start with a verb

- 'paths/data-science'
---

In PyTorch, **`.hastack()`** (short for horizontal stack)is a function used to concatenate two or more tensors along the horizontal axis (axis1). This operation is useful for combining data with the same number of rows but differing in the number of columns. It acts similarly to numpy's 'np.hastack()' and is particulary handy when you're working with data that needs to be concatenated side by side before being fed into a model for training or inference.
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
In PyTorch, **`.hastack()`** (short for horizontal stack)is a function used to concatenate two or more tensors along the horizontal axis (axis1). This operation is useful for combining data with the same number of rows but differing in the number of columns. It acts similarly to numpy's 'np.hastack()' and is particulary handy when you're working with data that needs to be concatenated side by side before being fed into a model for training or inference.
In PyTorch, **`.hstack()`** (short for horizontal stack) is a function used to concatenate two or more tensors along the horizontal axis (`axis=1`). This operation is helpful in combining data with the same number of rows but differing in the number of columns. It acts similarly to NumPy's `np.hstack()` and is particularly handy for data that needs to be concatenated side by side before being fed into a model for training or inference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed spelling mistakes and reframed the sentence a bit


The basic syntax of `.hstack()` in PyTorch is as falows:

```python
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
```python
```pseudo

Copy link
Collaborator

Choose a reason for hiding this comment

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

syntax is to be wrapped in the pseudo block


Where:

- `tensors` is a sequence of tesors with the same numbers of rows.
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
- `tensors` is a sequence of tesors with the same numbers of rows.
- `tensors`: A sequence of tensors with the same number of rows. All tensors must have the same number of dimensions and the same size in all dimensions except for the dimension corresponding to the horizontal stacking.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be elaborated

Where:

- `tensors` is a sequence of tesors with the same numbers of rows.
- The function returns a new tensor containing the horizontal concatenation of the imput tensors.
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
- The function returns a new tensor containing the horizontal concatenation of the imput tensors.
The function returns a new tensor containing the horizontal concatenation of the input tensors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No bullet point needed as it is not a parameter

b = torch.tensor([[5, 6],[7, 8]])

# Horizontal stack
c = toarch.hstack((a, b))
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
c = toarch.hstack((a, b))
c = torch.hstack((a, b))


# Exemple

Here's simple example demonstrating how '.hstack()' can be used to concatenate tensors:
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
Here's simple example demonstrating how '.hstack()' can be used to concatenate tensors:
Here's an example demonstrating how `.hstack()` can be used to concatenate tensors:

Comment on lines 58 to 68

# Codebyte Exemple

```python
import torch

# Create 1D tensors
a = torch.tensor([1, 2])
b = torch.tensor([3, 4])

# Horizontal stack
c = torch.tensor((a, b))

print(c)
```
In this Codebyte example, two 1-dimensional tensors are horizontally concatenated, showcasing how `.hstack()`seamlessly combines tensors not just in 2D but also in 1D tensors, further emphasizing the function's utility in handling tensors of varios dimensions as long as thay share the same number of rows (or are all 1-dimensional).




Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed since the Codecademy Compiler does not have PyTorch dependencies yet.

@clonymontana
Copy link
Author

Hello @mamtawardhani Thank you for the opportunity to contribute 😄

Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

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

Thank you for contributing to Codecademy Docs @clonymontana 😄

The entry looks good for a second round of review! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Indicates the PR was approved, merged, and pertains to Hacktoberfest new entry New entry or entries pytorch PyTorch status: review 1️⃣ completed status: under review Issue or PR is currently being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants