dimanche 10 février 2019

Return the number of the max consecutive elements in a list/ array in python

I'd like to find the max number of consecutive elements in an array or list. How can I achieve this?

array = np.random.randint(2, size=50)
array([1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0,
       0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0,
       0, 1, 1, 0, 1, 0])

So in this case, the number returned should be 5, as there are 5 consecutive zeros.




Aucun commentaire:

Enregistrer un commentaire