find_const_seq_long
- mdtools.numpy_helper_functions.find_const_seq_long(x, tol=1e-08, sort=False)[source]
Find the longest sequence of constant values in an array.
If there exist multiple sequences with the longest length, the first of them is returned.
- Parameters:
x (
array_like
) – 1-dimensional array in which to find the longest sequence of constant values.tol (
scalar
, optional) – Tolerance value within which consecutive elements of x are considered to be equal.sort (
bool
, optional) – IfTrue
, sort x before searching for sequences of constant values.
- Returns:
See also
get_const_seqs()
Get all sequences of constant values in an array.
find_const_seq_n()
Find the first sequence of at least n constant values in an array
Examples
>>> a = np.array([0, 4, 4, 4, 2, 2]) >>> mdt.nph.find_const_seq_long(a) (1, 3, 4.0) >>> mdt.nph.find_const_seq_long(a, sort=True) (3, 3, 4.0) >>> np.sort(a) array([0, 2, 2, 4, 4, 4])
Edge cases:
>>> a = np.array([]) >>> mdt.nph.find_const_seq_long(a, sort=True) (array([], dtype=int64), 0, array([], dtype=float64)) >>> a = np.ones(3) >>> mdt.nph.find_const_seq_long(a, sort=True) (0, 3, 1.0)