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

Creation of hsplit entry for pytorch #5556

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
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
57 changes: 57 additions & 0 deletions content/pytorch/concepts/tensor-operations/terms/hsplit/hsplit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
Title: '.hsplit()'
Description: 'Splits a tensor into multiple chunks.'
mamtawardhani marked this conversation as resolved.
Show resolved Hide resolved
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 **`.hsplit()`** method splits a tensor into multiple sub-tensors horizontally (column-wise) along a specified axis.

## Syntax

```pseudo
torch.hsplit(tensor, split_size_or_sections, dim=0)
```

- `tensor`: The tensor to be split.
- `split_size_or_sections`: The number of sub-tensors to be created or the size of each sub-tensor.
- `dim` (Optional): The axis along which to split the tensor. The default value is `0`.

## Example

The following example demonstrates the usage of the `.hsplit()` method:

```py
import torch

# Define a tensor
tensor = torch.tensor([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]])

# Split the tensor
sub_tensors = torch.hsplit(tensor, 2)

print(sub_tensors)
```[tensor([[1, 2, 3],
[5, 6, 7]]),

tensor([[4], [8], [12]])]

The above code produces the following output:

[tensor([[1, 2, 3],
[5, 6, 7]]),

tensor([[4], [8], [12]])]

The tensor is split into two sub-tensors along the columns. The first sub-tensor contains the first two columns of the original tensor, while the second sub-tensor contains the last two columns.
Loading