.vsplit()
Anonymous contributor
Published Jan 30, 2025
Contribute to Docs
In PyTorch, the .vsplit()
function divides a tensor into multiple sub-tensors vertically (row-wise). This function is particularly useful when a tensor needs to be divided into smaller chunks, keeping the number of rows consistent across each chunk.
Syntax
torch.vsplit(tensor, sections)
tensor
: The tensor to be split vertically.sections
: The value for this parameter can be either an integer or a list of integers.- If the value is an integer, the tensor is split into the specified number of equal parts.
- If the value is a list of integers, it specifies the indices where the tensor is to be split.
Example
The following example demonstrates the usage of the .vsplit()
function:
import torch# Define a tensorten = torch.tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]])# Split the tensor into 3 sub-tensors verticallyres = torch.vsplit(ten, 3)# Print the resultprint(res)
The above code produces the following output:
(tensor([[0, 1, 2]]), tensor([[3, 4, 5]]), tensor([[6, 7, 8]]))
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
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 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