12.3.2.2. Splitting arrayΒΆ

import numpy as np
rg = np.random.default_rng(1)
a = np.floor(10 * rg.random((2, 12)))
a

Out:

array([[5., 9., 1., 9., 3., 4., 8., 4., 5., 0., 7., 5.],
       [3., 7., 3., 4., 1., 4., 2., 2., 7., 2., 4., 9.]])
b = np.hsplit(a, 3)
b

Out:

[array([[5., 9., 1., 9.],
       [3., 7., 3., 4.]]), array([[3., 4., 8., 4.],
       [1., 4., 2., 2.]]), array([[5., 0., 7., 5.],
       [7., 2., 4., 9.]])]
c = np.hsplit(a, (3, 4))
c

Out:

[array([[5., 9., 1.],
       [3., 7., 3.]]), array([[9.],
       [4.]]), array([[3., 4., 8., 4., 5., 0., 7., 5.],
       [1., 4., 2., 2., 7., 2., 4., 9.]])]

Total running time of the script: ( 0 minutes 0.003 seconds)

Gallery generated by Sphinx-Gallery