[Numpy-discussion] breaking array indices

Mathew Yeates mat.yeates at gmail.com
Thu Jun 2 14:16:08 EDT 2011


thanks. My solution was much hackier.

-Mathew

On Thu, Jun 2, 2011 at 10:27 AM, Olivier Delalleau <shish at keba.be> wrote:
> I think this does what you want:
>
> def seq_split(x):
>   r = [0] + list(numpy.where(x[1:] != x[:-1] + 1)[0] + 1) + [None]
>   return [x[r[i]:r[i + 1]] for i in xrange(len(r) - 1)]
>
> -=- Olivier
>
> 2011/6/2 Mathew Yeates <mat.yeates at gmail.com>
>>
>> Hi
>> I have indices into an array I'd like split so they are sequential
>> e.g.
>> [1,2,3,10,11] -> [1,2,3],[10,11]
>>
>> How do I do this?
>>
>> -Mathew
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>



More information about the NumPy-Discussion mailing list