Time for action – splitting arrays
The following steps demonstrate arrays splitting:
Horizontal splitting: The ensuing code splits an array along its horizontal axis into three pieces of the same size and shape:
In: a Out: array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) In: hsplit(a, 3) Out: [array([[0], [3], [6]]), array([[1], [4], [7]]), array([[2], [5], [8]])]
Compare it with a call of the
split()
function, with extra parameteraxis=1
:In: split(a, 3, axis=1) Out: [array([[0], [3], [6]]), array([[1], [4], [7]]), array([[2], [5], [8]])]
Vertical splitting:
vsplit()
splits along the vertical axis:In: vsplit(a, 3) Out: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]
The
split()
function, withaxis=0
, also splits along the vertical axis:In: split(a, 3, axis=0) Out: [array([[0, 1, 2]]), array([[3, 4, 5]]), array([[6, 7, 8]])]
Depth-wise splitting: The
dsplit()
function, unsurprisingly...