Tsallaka zuwa abun ciki
Justice Tech School

Splitting Arrays

split divides an array into equal parts or at given indexes. hsplit and vsplit split by columns or rows.

Example
import numpy as np
a = np.arange(6)
print(np.split(a, 3))
print(np.split(a, [2, 4]))
m = np.arange(8).reshape(2, 4)
print(np.hsplit(m, 2))

Result

[array([0, 1]), array([2, 3]), array([4, 5])]
[array([0, 1]), array([2, 3]), array([4, 5])]
[array([[0, 1],
       [4, 5]]), array([[2, 3],
       [6, 7]])]

Exercise

Split into three parts.

np.split(a, )

Quiz Test

Which splits by columns?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.