[SciPy-User] Identify unique sequence data from array

otrov dejan.org at gmail.com
Thu Dec 23 13:59:41 EST 2010


> You could also check one element at a time. I think it will be
> faster, because it will break if comparison of the first element
> doesn't hold. Then, if you find such an occurrence, use Robert's
> method to double check that you found the true repetition period.

> Code:
>>>> a = [1,2,3,4,1,2,3,4,1,2,3,4]
>>>> a = numpy.array(a)
>>>> for i in range(1, 1+a.size/2):
> ...     if (a[0] == a[::i]).all(): print 'period is ',i
> ...     
> ... 
> period is  4

This works great!

For 2D if it's not obvious:

for i in range(1, 1+a.size/4):
    if (a[0,0] == a[::i,0]).all():
        do something


Thank you




More information about the SciPy-User mailing list