From c246b7a99c236695bfc270ac93877a41bc39d34c Mon Sep 17 00:00:00 2001 From: Sriparno Roy <89148144+Sriparno08@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:46:12 +0530 Subject: [PATCH] [Term Entry] PyTorch Tensors: .dstack() (#5750) * [Term Entry] PyTorch Tensors: .dstack() * Update dstack.md --------- --- .../concepts/tensors/terms/dstack/dstack.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 content/pytorch/concepts/tensors/terms/dstack/dstack.md diff --git a/content/pytorch/concepts/tensors/terms/dstack/dstack.md b/content/pytorch/concepts/tensors/terms/dstack/dstack.md new file mode 100644 index 00000000000..a742e09e9c5 --- /dev/null +++ b/content/pytorch/concepts/tensors/terms/dstack/dstack.md @@ -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]]]) +```