Run Length Array

API documentation

class npstructures.RunLengthArray(events, values, do_clean=False)[source]

Class for Run Length arrays

This is used to represent data where changes in values are rare. Behaves much like a normal NumPy array.

Should be constructed using one of the classmethods, not initialized directly

all(axis=-1, out=None)[source]

TODO, this can be sped up by assuming no empty runs

any(axis=-1, out=None)[source]

TODO, this can be sped up by assuming no empty runs

property ends: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]

All indices that ends a run of equal values

classmethod from_array(array: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) RunLengthArray[source]

Construct a RunLengthArray from a normal numpy array

Parameters:
arrayArrayLike

Normal numpy array

Returns:
‘RunLengthArray’
static join_runs(events: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], values: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) Tuple[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]][source]

Join succesive runs with the same value

Parameters:
eventsArrayLike
valuesArrayLike
Returns:
Tuple[ArrayLike, ArrayLike]
static remove_empty_intervals(events: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], values: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], delete_first: bool = True) Tuple[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]][source]

Remove any empty runs from a pair of indices and values.

Should be run before creating a runlength array from the events and values

Parameters:
eventsArrayLike
valuesArrayLike
delete_firstbool
Returns:
Tuple[ArrayLike, ArrayLike]
property size: int

Size of the array

property starts: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]

All idxs where the value changes

to_array() ndarray[source]

Convert the runlength array to a normal numpy array

Returns:
np.ndarray
property values: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]

All values that are not equal to previous value

Returns:
ArrayLike
class npstructures.RunLength2dArray(indices: RaggedArray, values: RaggedArray, row_len: int | None = None)[source]

Multiple RunLengthArrays of the same size. Behaves like a 2d numpy array

classmethod from_array(array: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) RunLength2dArray[source]

Construct a Runlength2dArray from a normal 2d numpy array

Parameters:
arrayArrayLike
Returns:
‘RunLength2dArray’
classmethod from_intervals(starts: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], ends: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], row_len: int, value=1) RunLength2dArray[source]

Construct a RunLength2dArray from a set of intervals

Each interval becomes a row in the 2d array

Parameters:
cls
startsArrayLike
endsArrayLike
row_lenint
value
Returns:
‘RunLength2dArray’
to_array() _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes][source]

Convert to a normal 2d numpy array

class npstructures.RunLengthRaggedArray(indices: RaggedArray, values: RaggedArray, row_len: int | None = None)[source]

Multiple row-lenght arrays of differing lengths

classmethod from_array(array)[source]

Construct a Runlength2dArray from a normal 2d numpy array

Parameters:
arrayArrayLike
Returns:
‘RunLength2dArray’
classmethod from_ragged_array(ragged_array: RaggedArray) RunLengthRaggedArray[source]

Construct runlengtharray from a RaggedArray

Parameters:
ragged_arrayRaggedArray
Returns:
RunLengthRaggedArray
static remove_empty_intervals(events: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], values: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) Tuple[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]][source]

Remove any empty runs from a pair of indices and values.

Should be run before creating a runlength array from the events and values

Parameters:
eventsArrayLike
valuesArrayLike
delete_firstbool
Returns:
Tuple[ArrayLike, ArrayLike]
to_array(ragged=True)[source]

Convert to a normal 2d numpy array