Jul-26-2020, 12:36 AM
np.where
returns a tuple. The first item of this tuple is an array of indecies where A
is occurred. So, we need to pass np.where(...)[0]
to the np.split
function. However, the first element of lst
is 'A' and we don't need to split array at this position. So, we just excluded the index of first occurrence of A
from splittng [1:]
-- means select all indecies but not the first (first is 0).Thus, [0] -- selects the first element of the tuple that is an array of indecies where
A
is occurred. and [1:]
selects all such indecies except the first.