Numpy – determining if an array contains a contiguous sequence of elements of length N

  Kiến thức lập trình

I’m trying to find a way to check if an array has a sequence of numbers like :

[1,2,3,4,4,4,4,5,6,7]

Unlike here, I don’t mind where they are, just that there is a repeat (of any number) of length N. I could do this in an iterative way with a counter and sliding window but I couldn’t figure out how to convert this into numpy to vectorise it.

LEAVE A COMMENT