How To Split An Array In Unequal Pieces?
I have an array like this import numpy as np x = np.array([1, 2, 3, 99, 99, 3, 2, 1]) I want to split it in three pieces x1 = array([1, 2, 3]) x2 = array([99, 99]) x3 = array([3,
Solution 1:
You can use np.split
:
x = np.array([1, 2, 3, 99, 99, 3, 2, 1])
x1, x2, x3 = np.split(x, [3, 5])
[3, 5]
thereby specifies the indexes at which you want to split.
That yields
x1
array([1, 2, 3])
x2
array([99, 99])
x3
array([3, 2, 1])
Post a Comment for "How To Split An Array In Unequal Pieces?"