Suppose I have this NumPy array:
a = np.array([0, 3, 5, 5, 0, 10, 14, 15, 56, 0, 12, 23, 45, 23, 12, 45, 0, 1, 0, 2, 3, 4, 0, 0 ,0]) <
a = np.array([0, 3, 5, 5, 0, 10, 14, 15, 56, 0, 12, 23, 45, 23, 12, 45, 0, 1, 0, 2, 3, 4, 0, 0 ,0])
NumPy's split() and where() in a list compehension:
split()
where()
[x[x!=0] for x in np.split(a, np.where(a==0)[0]) if len(x[x!=0])] [array([3, 5, 5]), array([10, 14, 15, 56]), array([12, 23, 45, 23, 12, 45]), array([1]), array([2, 3, 4])]