I am running this code, and I used indices in the order of (2, 1) on purpose.
a1 = np.arange(30).reshape(5, 6)
print(a1)
a, b, c = np.split(a1, (2, 1))
print("A is\n",a)
print("B is\n",b)
print("C is\n",c)
And this is the output:
[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]
[24 25 26 27 28 29]]
A is
[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]]
B is
[]
C is
[[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]
[24 25 26 27 28 29]]
I understand that I am getting b = [] because I used indices (2, 1). But why am I getting the c output from 1st index? Thank you for your time
>Solution :
According to the documentation:
If
indices_or_sectionsis a 1-D array of sorted integers, the entries
indicate where alongaxisthe array is split. For example,
[2, 3]would, foraxis=0, result in
- ary[:2] - ary[2:3] - ary[3:]
I.e., your example a, b, c = np.split(a1, (2, 1)) translates to:
a = a1[:2]
b = a1[2:1]
c = a1[1:]