NumPy Vertical Splitting: numpy.vsplit() function

It is used to split an array into multiple sub-arrays row-wise(vertically).

Syntax:

numpy.vsplit(array, sections)

Examples:

For 2-D Array:

import numpy as np
a=np.array([[1,2],[3,4],[5,6],[7,8]])
b=np.vsplit(a,4)
print(b)

Output:

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

Note: Vertical Splitting is not possible in a 1-D Array. vsplit() is alternate to vstack().

Tue, 09/07/2021 - 18:53

Authored by

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.