mymesh.utils.SortRaggedByLength#

mymesh.utils.SortRaggedByLength(In, return_idx=False, return_inv=False, return_separators=False)[source]#

Sorted a ragged list of lists by the length of each sublist

Parameters:
  • In (list) – List of lists to be sorted

  • return_idx (bool, optional) – Returns the indices of each row of In in the order that they’re sorted into Out, by default False.

  • return_inv (bool, optional) – Returns the indices that reverse the sorting operation, by default False.

  • return_separators (bool, optional) – Returns the indices that separate sections of the list by length. Determining these separators requires a small amount of additional work, by default False.

Returns:

  • Out (list) – List of lists sorted by row length

  • idx (np.ndarray, optional) – Indices used to reorder In to Out. These are the indices of each row of In in the order that they’re sorted into Out. Returned if return_idx is True.

  • inv (np.ndarray, optional) – Indices to recover the original List (in) from the output (Out). Return if return_inv us True.

  • separators (np.ndarray, optional) – Indices of Out that separate sections of the list by length. These separators will always include 0 as the first separator and len(Out) as the last separator. With the exception of the last separator, each separator is the start of a new section and are set such that the sublists of equal-length lists can be accessed by slices with two adjacent separators.

Examples

>>> In = [[0,1], [2, 3, 4, 5], [6, 7], [8, 9, 10]]
>>> Out, idx, inv = utils.SortRaggedByLength(In, return_idx=True, return_inv=True)
>>> Out
>>> [In[i] for i in idx] == Out
>>> [Out[i] for i in inv] == In