[Numpy-discussion] breaking array indices

Olivier Delalleau shish@keba...
Thu Jun 2 12:27:49 CDT 2011


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110602/0d7c3a3b/attachment.html 


More information about the NumPy-Discussion mailing list