Skip to content

Commit

Permalink
[Term Entry] PyTorch Tensors: .dstack() (#5750)
Browse files Browse the repository at this point in the history
* [Term Entry] PyTorch Tensors: .dstack()

* Update dstack.md

---------
  • Loading branch information
Sriparno08 authored Dec 6, 2024
1 parent 48c2741 commit c246b7a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions content/pytorch/concepts/tensors/terms/dstack/dstack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
Title: '.dstack()'
Description: 'Stacks a sequence of tensors depthwise along the third axis, creating a new tensor.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Deep Learning'
- 'Machine Learning'
- 'Functions'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'py-torch-for-classification'
---

In PyTorch, the **`.dstack()`** function stacks a sequence of tensors depthwise, i.e., along the third axis (axis=2), creating a new tensor.

## Syntax

```pseudo
torch.dstack(tensors, *, out=None)
```

- `tensors`: A sequence (e.g., list or tuple) of tensors to be stacked depthwise along the third axis.
- `out` (Optional): A tensor where the output will be stored, if provided.

## Example

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

```py
import torch

# Create tensors
ten1 = torch.tensor([11, 22, 33])
ten2 = torch.tensor([12, 23, 34])

# Stack the tensors depthwise
res = torch.dstack((ten1, ten2))

print(res)
```

The above code produces the following output:

```shell
tensor([[[11, 12],
[22, 23],
[33, 34]]])
```

0 comments on commit c246b7a

Please sign in to comment.