Splitting Arrays: split, hsplit & vsplit

Splitting is the operation that breaks one NumPy array into a list of smaller sub-arrays, either into equal pieces or at positions you choose — the exact inverse of stacking arrays together.

Learn Splitting Arrays: split, hsplit & vsplit in our free NumPy course — a beginner-friendly interactive lesson with worked examples, a practice exercise…

Part of the free Numpy course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

You'll learn np.split for the even case, np.array_split for uneven sizes, the hsplit/vsplit shortcuts for 2D arrays, and how to cut at specific indices.

The workhorse is np.split(arr, n) . It returns a list of n sub-arrays of equal length. The one rule: the array length must divide evenly by n , otherwise NumPy raises a ValueError .

Real data rarely divides cleanly. np.array_split(arr, n) is the forgiving version: it splits into n parts even when the length is not divisible. The earlier pieces get one extra element so that everything fits.

For 2D arrays, two shortcuts pick the axis for you. np.vsplit cuts rows (axis 0, the vertical direction) and np.hsplit cuts columns (axis 1, the horizontal direction). Both are just np.split with the axis fixed.

Passing a list of indices instead of a number cuts the array before each position. This never requires an even division.

Replace ___ with the right function so the columns of a 2D array are split into two halves.

Answer: hsplit — the horizontal split works on columns (axis 1).

❌ "array split does not result in an equal division"

✅ Fix: use array_split, which allows uneven pieces:

hsplit cuts columns, vsplit cuts rows — easy to swap by accident.

✅ Fix: remember H split is H orizontal (columns, axis 1) and V split is V ertical (rows, axis 0).

✅ Fix: index into the list first, e.g. np.split(arr, 3)[0] + 1 .

You have 10 samples and want to process them in 3 batches. Use the forgiving splitter so it works even though 10 is not divisible by 3, then print each batch and its size.

Lesson complete — you can break arrays apart!

You can split evenly with np.split , handle uneven sizes with np.array_split , cut rows and columns with vsplit / hsplit , and slice at exact indices.

🚀 Up next: The axis Parameter Explained — the single idea that ties splitting, stacking, and aggregation together.

Practice quiz

What does np.split(arr, n) return?

  • A single concatenated array
  • A list of n sub-arrays
  • The sorted array
  • A scalar

Answer: A list of n sub-arrays. np.split returns a Python list of n sub-arrays.

What happens if np.split cannot divide the array evenly?

  • It pads with zeros
  • It silently drops elements
  • It raises a ValueError
  • It returns one array

Answer: It raises a ValueError. np.split requires an even division and raises a ValueError otherwise.

How does np.array_split handle a length that does not divide evenly?

  • It splits anyway, making earlier pieces one element larger
  • It raises an error
  • It returns an empty list
  • It rounds the length

Answer: It splits anyway, making earlier pieces one element larger. array_split is the forgiving version; earlier pieces get one extra element.

Along which axis does np.hsplit split?

  • axis 0 (rows)
  • No axis
  • axis 2
  • axis 1 (columns)

Answer: axis 1 (columns). hsplit splits horizontally along axis 1 (columns).

Along which axis does np.vsplit split?

  • axis 0 (rows)
  • axis 1 (columns)
  • axis 2
  • Every axis

Answer: axis 0 (rows). vsplit splits vertically along axis 0 (rows).

What does np.split(arr, [2, 5]) do?

  • Splits into 2 then 5 pieces
  • Cuts before index 2 and before index 5
  • Removes indices 2 and 5
  • Raises an error

Answer: Cuts before index 2 and before index 5. A list of indices cuts the array before each position, giving three pieces here.

Do the pieces returned by np.split share memory with the original?

  • Never
  • Only for 1D arrays
  • Yes, they are views like basic slices
  • Only after .copy()

Answer: Yes, they are views like basic slices. Like slicing, split returns views; editing a piece changes the original.

Which function should you use when the size might not divide evenly?

  • np.split
  • np.array_split
  • np.hsplit
  • np.concatenate

Answer: np.array_split. array_split never errors on uneven sizes, so reach for it when unsure.

hsplit(arr, 2) is equivalent to which general call?

  • np.split(arr, 2, axis=0)
  • np.array_split(arr, 2)
  • np.vsplit(arr, 2)
  • np.split(arr, 2, axis=1)

Answer: np.split(arr, 2, axis=1). hsplit fixes the axis at 1, so it equals split(arr, 2, axis=1).

What is splitting the inverse of?

  • Sorting
  • Indexing
  • Stacking arrays together
  • Reshaping

Answer: Stacking arrays together. Splitting breaks one array into pieces, the exact inverse of stacking them together.