clouddrift.ragged.regular_to_ragged

clouddrift.ragged.regular_to_ragged#

clouddrift.ragged.regular_to_ragged(array: ndarray, fill_value: float = nan) tuple[ndarray, ndarray][source]#

Convert a two-dimensional array to a ragged array. Fill values in the input array are excluded from the output ragged array.

Parameters#

arraynp.ndarray

A two-dimensional array.

fill_valuefloat, optional

Fill value used to determine the bounds of contiguous segments.

Returns#

tuple[np.ndarray, np.ndarray]

A tuple of the ragged array and the size of each row.

Examples#

By default, NaN values found in the input regular array are excluded from the output ragged array:

>>> regular_to_ragged(np.array([[1, 2], [3, np.nan], [4, 5]]))
(array([1., 2., 3., 4., 5.]), array([2, 1, 2]))

Alternatively, a different fill value can be specified:

>>> regular_to_ragged(np.array([[1, 2], [3, -999], [4, 5]]), fill_value=-999)
(array([1, 2, 3, 4, 5]), array([2, 1, 2]))

See Also#

ragged_to_regular()