Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.vsplit

Splits an array into multiple sub-arrays row-wise. It always operates along the first axis and accepts either an equal-section count or explicit split positions.

How it works

np.vsplit divides an array at row boundaries. An integer requests that many equal sections, while an array-like sequence supplies split positions; the operation always uses the first axis, including for arrays with more than two dimensions.

Syntax

numpy.vsplit(ary, indices_or_sections)

Parameters

NameTypeDescription
aryarray_likeThe array to split. If ary is a 1-D array, it is treated as a row vector.
indices_or_sectionsint or 1-D arrayIf an integer, the number of equal sections; if an array of sorted integers, the split positions along the first axis.

Returns

A list of sub-arrays.

Key points

  • Use np.vsplit to turn one array into a list of row-oriented sub-arrays.
  • Its behavior matches np.split with axis=0.
  • For multidimensional input, only the first dimension is partitioned; other dimensions remain intact.

Common mistakes

  • For higher-dimensional input, vsplit still splits only the first dimension, not an arbitrary axis.

Example: Split rows evenly

import numpy as np

x = np.arange(12).reshape(3, 4)
parts = np.vsplit(x, 3)

print([part.shape for part in parts])
# [(1, 4), (1, 4), (1, 4)]

This creates three row-wise sub-arrays, each containing one row of the input.

When to use it

Equal row batches

Partition tabular data into equal row blocks for batch processing.

Explicit row boundaries

Cut a multidimensional tensor at known first-axis boundaries.

Vector partitioning

Separate a one-dimensional sequence into vertical-style row segments.

Interview questions

QWhat does np.vsplit do, and how is it related to np.split?

np.vsplit(ary, indices_or_sections) splits an array into multiple sub-arrays along the first axis. It is equivalent to calling np.split(ary, indices_or_sections, axis=0).

Follow-up: How does an integer differ from explicit indices? An integer requests equal sections, whereas an index sequence marks the boundaries and can produce uneven sections.

QWhat forms can indices_or_sections take?

An integer specifies the number of equal sections. A sequence such as [3, 6] specifies row boundaries, producing sections before 3, from 3 to 6, and after 6.

Follow-up: What happens when a boundary reaches the end? The resulting list can include an empty trailing array, as shown by the documented example using indices [3, 6].

QHow does vsplit behave for arrays with more than two dimensions?

The first axis is always selected, regardless of the array's dimensionality. Thus, for a three-dimensional array, each returned array preserves the remaining dimensions while receiving a subset of the first-axis entries.

Follow-up: Which function should be used when the desired axis is not axis 0? Use np.split and pass the required axis explicitly.

  • numpy.array_split
  • numpy.split
  • numpy.hsplit

Source: numpy.vsplit — NumPy v2.2 Manual. Checked 2026-10-15.