find_contiguous

pydl.pydlutils.math.find_contiguous(x)[source]

Find the longest sequence of contiguous non-zero array elements.

Parameters:
xnumpy.ndarray

A 1d array. A dtype of bool is preferred although any dtype where the operation if x[k]: is well-defined should work.

Returns:
list

A list of indices of the longest contiguous non-zero sequence.

Examples

>>> import numpy as np
>>> from pydl.pydlutils.math import find_contiguous
>>> find_contiguous(np.array([0,1,1,1,0,1,1,0,1]))
[1, 2, 3]