[Numpy-discussion] array equivalent to string.split(sep)

David Huard david.huard at gmail.com
Wed Aug 16 10:16:59 EDT 2006


Hi,

I have a time series that I want to split into contiguous groups
differentiated by a condition. I didn't find a vectorized way to that, so I
ended up doing a for loop...

I know there are split functions that split arrays into equal lengths
subarrays, but is there a swell trick to return a sequence of arrays
separated by a condition ?

For instance, I would like to do something like:

>>> a = array([1,1,1,1,1,5,1,1,1,1,1,1,6,2,1,1])
>>> a.argsplit(a>1)
[[0,1,2,3,4], [6,7,8,9,10,11], [14,15]]

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060816/a424cf32/attachment.html>


More information about the NumPy-Discussion mailing list