``````

In [1]:

import numpy as np

``````
``````

In [2]:

a = np.arange(16).reshape(4, 4)
print(a)

``````
``````

[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [3]:

a_split = np.split(a, 2)

``````
``````

In [4]:

print(type(a_split))

``````
``````

<class 'list'>

``````
``````

In [5]:

print(len(a_split))

``````
``````

2

``````
``````

In [6]:

print(a_split[0])

``````
``````

[[0 1 2 3]
[4 5 6 7]]

``````
``````

In [7]:

print(a_split[1])

``````
``````

[[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [8]:

print(type(a_split[0]))

``````
``````

<class 'numpy.ndarray'>

``````
``````

In [9]:

print(a)

``````
``````

[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [10]:

a0, a1 = np.split(a, 2)

``````
``````

In [11]:

print(a0)

``````
``````

[[0 1 2 3]
[4 5 6 7]]

``````
``````

In [12]:

print(a1)

``````
``````

[[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [13]:

# np.split(a, 3)
# ValueError: array split does not result in an equal division

``````
``````

In [14]:

a0, a1, a2 = np.split(a, [1, 3])

``````
``````

In [15]:

print(a0)

``````
``````

[[0 1 2 3]]

``````
``````

In [16]:

print(a1)

``````
``````

[[ 4  5  6  7]
[ 8  9 10 11]]

``````
``````

In [17]:

print(a2)

``````
``````

[[12 13 14 15]]

``````
``````

In [18]:

a0, a1 = np.split(a, [1])

``````
``````

In [19]:

print(a0)

``````
``````

[[0 1 2 3]]

``````
``````

In [20]:

print(a1)

``````
``````

[[ 4  5  6  7]
[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [21]:

a0, a1 = np.split(a, 2, 0)

``````
``````

In [22]:

print(a0)

``````
``````

[[0 1 2 3]
[4 5 6 7]]

``````
``````

In [23]:

print(a1)

``````
``````

[[ 8  9 10 11]
[12 13 14 15]]

``````
``````

In [24]:

a0, a1 = np.split(a, 2, 1)

``````
``````

In [25]:

print(a0)

``````
``````

[[ 0  1]
[ 4  5]
[ 8  9]
[12 13]]

``````
``````

In [26]:

print(a1)

``````
``````

[[ 2  3]
[ 6  7]
[10 11]
[14 15]]

``````
``````

In [27]:

# np.split(a, 2, 2)
# IndexError: tuple index out of range

``````
``````

In [28]:

a_3d = np.arange(24).reshape(2, 3, 4)
print(a_3d)

``````
``````

[[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]]

[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]

``````
``````

In [29]:

print(a_3d.shape)

``````
``````

(2, 3, 4)

``````
``````

In [30]:

a0, a1 = np.split(a_3d, 2, 0)

``````
``````

In [31]:

print(a0)

``````
``````

[[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]]]

``````
``````

In [32]:

print(a1)

``````
``````

[[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]

``````
``````

In [33]:

a0, a1 = np.split(a_3d, [1], 2)

``````
``````

In [34]:

print(a0)

``````
``````

[[[ 0]
[ 4]
[ 8]]

[[12]
[16]
[20]]]

``````
``````

In [35]:

print(a1)

``````
``````

[[[ 1  2  3]
[ 5  6  7]
[ 9 10 11]]

[[13 14 15]
[17 18 19]
[21 22 23]]]

``````