[Numpy-discussion] breaking array indices

Mathew Yeates mat.yeates@gmail....
Thu Jun 2 13:16:08 CDT 2011


thanks. My solution was much hackier.

-Mathew

On Thu, Jun 2, 2011 at 10:27 AM, Olivier Delalleau <shish@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@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@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


More information about the NumPy-Discussion mailing list