.dstack()
Anonymous contributor
Published Dec 6, 2024
Contribute to Docs
In PyTorch, the .dstack()
function stacks a sequence of tensors depthwise, i.e., along the third axis (axis=2), creating a new tensor.
Syntax
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:
import torch# Create tensorsten1 = torch.tensor([11, 22, 33])ten2 = torch.tensor([12, 23, 34])# Stack the tensors depthwiseres = torch.dstack((ten1, ten2))print(res)
The above code produces the following output:
tensor([[[11, 12],[22, 23],[33, 34]]])
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Free course
Intro to PyTorch and Neural Networks
Learn how to use PyTorch to build, train, and test artificial neural networks in this course.Intermediate3 hours - Course
PyTorch for Classification
Build AI classification models with PyTorch using binary and multi-label techniques.With CertificateBeginner Friendly3 hours