[Numpy-discussion] breaking array indices

Olivier Delalleau shish at keba.be
Thu Jun 2 13:27:49 EDT 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 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110602/0d7c3a3b/attachment.html>


More information about the NumPy-Discussion mailing list