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

NumPy · Function

np.split

Splits an ndarray into multiple sub-arrays along a chosen axis. It supports equal-count splitting or explicit sorted boundaries, and returns views of the original array.

How it works

Pass an array, either a number of equal sections or sorted split positions, and the axis to divide. The function returns a list of sub-arrays that are views into the original array; integer section counts must divide the selected axis evenly.

Syntax

numpy.split(ary, indices_or_sections, axis=0)

Parameters

NameTypeDescription
aryndarrayArray to be divided into sub-arrays.
indices_or_sectionsint or 1-D arrayAn integer N for equal sections, or a one-dimensional array of sorted integers marking split positions.
axisint, optionalDimension along which to split; defaults to 0.

Returns

sub-arrays — list of ndarrays: a list of sub-arrays as views into ary.

Key points

  • The function partitions one ndarray into multiple sub-arrays without making them copies.
  • An integer argument specifies how many equally sized sections to create.
  • A sorted one-dimensional integer sequence gives the split boundaries.
  • Splitting uses axis 0 unless another axis is supplied.
  • The result is a list, and each element remains linked to the source array's storage.

Common mistakes

  • An integer section count raises ValueError when the selected axis length cannot be divided evenly.
  • When supplying explicit boundaries, provide them as a one-dimensional sorted integer sequence.

Example: Split rows and columns

import numpy as np

x = np.arange(12).reshape(3, 4)
rows = np.split(x, 3, axis=0)
columns = np.split(x, 2, axis=1)

print(rows[0])
print(columns[0])

The array is divided evenly into three row sub-arrays and two column sub-arrays.

When to use it

Equal-sized batching

Divide rows or columns into equally sized blocks for batch processing or parallel work.

Boundary-based segmentation

Cut an array at known offsets to extract segments with specific lengths.

Axis-wise partitioning

Partition multidimensional data along a selected dimension.

Interview questions

QWhat does numpy.split return?

It returns a list of sub-arrays produced by dividing ary along axis. The returned sub-arrays are views into the original array, not independent copies.

Follow-up: How can you preserve unequal final sections? Use explicit sorted integer boundaries, or choose numpy.array_split when an integer count should allow unequal sections.

QWhat is the difference between an integer and a sequence for indices_or_sections?

An integer N requests N equal sections along the selected axis. If equal division is impossible, the function raises ValueError.

Follow-up: What happens with explicit boundaries beyond the axis length? The documented example shows that they can produce an empty trailing sub-array.

QHow does axis affect the result?

axis selects the dimension being divided and defaults to 0. For a two-dimensional array, axis=0 splits rows, while axis=1 splits columns.

Follow-up: How would you split a three-dimensional array along its last dimension? Pass axis=-1, provided that dimension and the requested boundaries are valid.

  • numpy.array_split
  • numpy.hsplit
  • numpy.vsplit
  • numpy.dsplit

Source: numpy.split. Checked 2026-10-15.