.row_stack()
Anonymous contributor
Published Dec 24, 2024
Contribute to Docs
In PyTorch, the .row_stack()
function stacks or arranges a sequence of tensors vertically (row-wise). It is an alias or alternative for the .vstack()
function.
Syntax
torch.row_stack(tensors, *, out=None)
tensors
: The sequence of tensors to be stacked vertically.out
(Optional): A tensor to store the output. It must have the correct shape to accommodate the result.
Example
The following example demonstrates the usage of the .row_stack()
function:
import torch# Create two tensorsten1 = torch.tensor([12, 23, 34])ten2 = torch.tensor([45, 56, 67])# Stack the tensors verticallyres = torch.row_stack((ten1, ten2))# Print the resultant tensorprint(res)
The above code produces the following output:
tensor([[12, 23, 34],[45, 56, 67]])
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
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 hours - 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