NumPy split(): How to Split Arrays in Python

To split a NumPy array, call np.split(arr, n) for n equal pieces or np.split(arr, [i, j]) to cut at specific indices. When the length doesn’t divide evenly, use np.array_split() instead, which allows unequal pieces:

np.split(np.arange(6), 3)        # [array([0, 1]), array([2, 3]), array([4, 5])]
np.array_split(np.arange(7), 3)  # sizes 3, 2, 2

In this tutorial, we’ll cover NumPy split from the basics to 2D arrays. I ran every example with Python 3.12.5 and NumPy 2.5.3.

Split a NumPy array into equal parts with np.split()

Give np.split() an integer and it returns a list of that many equal sub-arrays. Here I’m splitting a year of monthly sales into quarters:

import numpy as np

# Monthly sales in USD, January to December 2026
sales = np.array([410.50, 389.25, 455.00, 472.75, 498.10, 530.00,
                  561.40, 549.90, 512.30, 488.00, 601.25, 712.80])

q1, q2, q3, q4 = np.split(sales, 4)      # 4 equal pieces
print("Q1:", q1)
print("Q4:", q4)
print("Q4 total: $" + format(q4.sum(), ".2f"))

Output:

Q1: [410.5  389.25 455.  ]
Q4: [488.   601.25 712.8 ]
Q4 total: $1802.05
Command Prompt output of NumPy split dividing 12 monthly sales values into four quarter arrays
Twelve months split into four arrays of three, so each quarter can be summed on its own.

The result is a plain Python list you can unpack or index. New to building arrays? Start with creating NumPy arrays in Python.

Split a NumPy array at specific indices

Pass a list of indices instead of a count, and NumPy cuts before each index. [3, 7] gives a[:3], a[3:7] and a[7:]:

import numpy as np

days = np.arange(1, 11)                  # order counts for days 1-10
first, middle, last = np.split(days, [3, 7])
print(first, middle, last)

print(np.split(days, [3, 3, 20]))        # repeated and out-of-range indices

Output:

[1 2 3] [4 5 6 7] [ 8  9 10]
[array([1, 2, 3]), array([], dtype=int64), array([ 4,  5,  6,  7,  8,  9, 10]), array([], dtype=int64)]

Repeated or out-of-range indices don’t raise an error; they just produce empty arrays. It’s the same slicing logic as NumPy array indexing.

What’s the difference between np.split() and np.array_split()?

The only difference is uneven lengths. np.split() refuses, while np.array_split() gives the first pieces one extra element:

import numpy as np

orders = np.arange(101, 111)             # 10 order IDs

try:
    np.split(orders, 4)
except ValueError as err:
    print("np.split:", err)

for part in np.array_split(orders, 4):
    print("array_split:", part, "size", part.size)

Output:

np.split: array split does not result in an equal division
array_split: [101 102 103] size 3
array_split: [104 105 106] size 3
array_split: [107 108] size 2
array_split: [109 110] size 2
Command Prompt output of np.split raising ValueError on an uneven split and np.array_split returning pieces of size 3, 3, 2 and 2
Ten order IDs into four parts: np.split() raises a ValueError, np.array_split() returns sizes 3, 3, 2 and 2.

I use np.split() when an uneven length means bad data, because the error catches it early. For batching, np.array_split() is the safer default.

Split 2D and 3D arrays with hsplit, vsplit and dsplit

Both functions take axis: 0 splits rows, 1 splits columns. The shortcuts read better:

  • np.vsplit(a, n) splits rows (axis 0)
  • np.hsplit(a, n) splits columns (axis 1)
  • np.dsplit(a, n) splits depth (axis 2, 3D arrays only)
import numpy as np

# Rows = 4 regions, columns = 6 months of 2026 sales (thousands of USD)
table = np.arange(1, 25).reshape(4, 6)

east, west = np.vsplit(table, 2)         # same as np.split(table, 2, axis=0)
h1, h2 = np.hsplit(table, 2)             # same as np.split(table, 2, axis=1)
print("vsplit top half shape:", east.shape)
print("hsplit first half:\n", h1)

cube = np.arange(24).reshape(2, 3, 4)
print("dsplit shapes:", [p.shape for p in np.dsplit(cube, 2)])

Output:

vsplit top half shape: (2, 6)
hsplit first half:
 [[ 1  2  3]
 [ 7  8  9]
 [13 14 15]
 [19 20 21]]
dsplit shapes: [(2, 3, 2), (2, 3, 2)]
Command Prompt output of NumPy vsplit and hsplit on a 4 by 6 sales table and dsplit on a 3D array
vsplit keeps all six months for half the regions; hsplit keeps every region for the first three months.

Print .shape after each split to confirm the axis; the NumPy shape attribute explains how to read it.

Split a NumPy array into chunks of a fixed size

np.split() takes a number of pieces, not a piece size. To get chunks of 4, pass the cut points with range(); the last chunk holds what’s left:

import numpy as np

readings = np.arange(1, 15)              # 14 sensor readings
size = 4
chunks = np.split(readings, range(size, len(readings), size))
for c in chunks:
    print(c)

Output:

[1 2 3 4]
[5 6 7 8]
[ 9 10 11 12]
[13 14]

For plain lists rather than arrays, see splitting a Python list into evenly sized chunks.

Are the split arrays copies or views?

They’re views of the original array, so writing to a piece changes the source. Call .copy() when you need independent pieces:

import numpy as np

prices = np.array([19.99, 24.50, 7.25, 12.00])
left, right = np.split(prices, 2)
left[0] = 0.00                           # edits the original too
print(prices)

safe = [p.copy() for p in np.split(prices, 2)]
safe[1][0] = 99.00
print(prices)                            # unchanged this time

Output:

[ 0.   24.5   7.25 12.  ]
[ 0.   24.5   7.25 12.  ]

To put the pieces back together, use NumPy concatenate, which is the reverse of a split.

Fix ‘numpy.ndarray’ object has no attribute ‘split’

This error means you called the string method .split() on an array. Arrays don’t have it, even when they hold text. Split each string with np.char.split() or a list comprehension:

import numpy as np

cities = np.array(["Austin,TX", "Denver,CO", "Boston,MA"])

try:
    cities.split(",")
except AttributeError as err:
    print("AttributeError:", err)

print(np.char.split(cities, ","))                # element-wise split
print([c.split(",") for c in cities.tolist()])   # plain Python lists
print(hasattr(np.strings, "split"))

Output:

AttributeError: 'numpy.ndarray' object has no attribute 'split'
[list(['Austin', 'TX']) list(['Denver', 'CO']) list(['Boston', 'MA'])]
[['Austin', 'TX'], ['Denver', 'CO'], ['Boston', 'MA']]
False
Command Prompt output of the numpy.ndarray has no attribute split error and the np.char.split fix on an array of city strings
The method call fails, while np.char.split() and a list comprehension both split every string.

On NumPy 2.5.3, the newer np.strings module has no split(), so np.char.split() is still the one to use. If you only need a list of strings, see converting a NumPy array to a list of strings.

NumPy split functions compared

FunctionSplits alongUneven OK?
np.split(a, n)Any axis (default 0)No, ValueError
np.array_split(a, n)Any axis (default 0)Yes
np.vsplit(a, n)Rows (axis 0)No
np.hsplit(a, n)Columns (axis 1)No
np.dsplit(a, n)Depth (axis 2)No

If you’re working through NumPy, these are good next reads:

Frequently asked questions

How do I split a NumPy array into equal parts?

Use np.split(arr, n). The length along the axis must divide evenly by n.

Why does np.split() say the split does not result in an equal division?

The length isn’t divisible by the number of pieces. Use np.array_split() or pick a different count.

How do I split a NumPy array at an index?

Pass a list of indices, for example np.split(arr, [3, 7]) returns three pieces.

How do I split a 2D array by columns?

Use np.hsplit(arr, n) or np.split(arr, n, axis=1).

How do I fix ‘numpy.ndarray’ object has no attribute ‘split’?

Arrays have no .split() method. Use np.char.split(arr, sep) or split each string in a list comprehension.

Where is numpy.split documented?

See numpy.split in the NumPy docs.