clouddrift.ragged.obs_index_to_row

clouddrift.ragged.obs_index_to_row#

clouddrift.ragged.obs_index_to_row(index: int | list[int] | ndarray | DataArray, rowsize: list[int] | ndarray | DataArray) list[source]#
Obtain a list of row indices from a list of observation indices of a ragged array.

A ragged array is constituted of rows of different sizes indicated by rowsize and is also constituted of a continuous sequence of observations with indices 0 to its length - 1. This function allows the user to obtain the row index of a given observation given its index. This answers the question: “In which row is an observation located?”

Parameters#

indexint or list or np.ndarray

A integer observation index or a list of observation indices of a ragged array.

rowsizelist or np.ndarray or xr.DataArray

A sequence of row sizes of a ragged array.

Returns#

list

A list of row indices.

Examples#

To obtain the row index of observation with index 5 within a ragged array of three consecutive rows of sizes 2, 4, and 3:

>>> obs_index_to_row(5, [2, 4, 3])
[1]

To obtain the row indices of observations with indices 0, 2, and 4 within a ragged array of three consecutive rows of sizes 2, 4, and 3:

>>> obs_index_to_row([0, 2, 4], [2, 4, 3])
[0, 1, 1]