Features.sort

Features.sort(by=None, reverse=False, *, useLog=None)

Arrange the features in this object.

This sort is stable, meaning the initial feature order is retained for features that evaluate as equal.

Parameters:
  • by (identifier(s), function, None) –

    Based on the parameter type:

    • identifier(s) - a single point index or name or a list of point indices and/or names. For lists, sorting occurs according to the first index with ties being broken in the order of the subsequent indices. Sort follows the natural ordering of the values in the identifier(s).

    • function - a scorer or comparator function. Must take either one or two positional arguments accepting feature views.

    • None - sort by the feature names.

  • reverse (bool) – Reverse the sorted order.

  • useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.

See also

permute

Examples

Sort by feature names.

>>> lst = [[64, 67, 64],
...        [68, 71, 66],
...        [73, 71, 70],
...        [45, 40, 51]]
>>> fts = ['Denver', 'Boulder', 'Fort Collins']
>>> highTemps = nimble.data(lst, featureNames=fts)
>>> highTemps.features.sort()
>>> highTemps
<Matrix 4pt x 3ft
     Boulder  Denver  Fort Collins
   ┌──────────────────────────────
 0 │    67      64         64
 1 │    71      68         66
 2 │    71      73         70
 3 │    40      45         51
>

Sort by points.

>>> lst = [[3, 1, 2, 0, 2],
...        [100, 1, 10, 0, 11],
...        [200, 2, 20, 0, 21],
...        [300, 3, 30, 0, 31]]
>>> orders = nimble.data(lst)
>>> orders.features.sort(0)
>>> orders
<Matrix 4pt x 5ft
     0  1  2   3    4
   ┌──────────────────
 0 │ 0  1   2   2    3
 1 │ 0  1  10  11  100
 2 │ 0  2  20  21  200
 3 │ 0  3  30  31  300
>

Sort using function.

>>> lst = [[64, 67, 64],
...        [68, 71, 66],
...        [73, 71, 70],
...        [45, 40, 51]]
>>> fts = ['Denver', 'Boulder', 'Fort Collins']
>>> highTemps = nimble.data(lst, featureNames=fts)
>>> def averageHighTemp(ft):
...     return nimble.calculate.mean(ft)
>>> highTemps.features.sort(averageHighTemp, reverse=True)
>>> highTemps
<Matrix 4pt x 3ft
     Fort Collins  Denver  Boulder
   ┌──────────────────────────────
 0 │      64         64       67
 1 │      66         68       71
 2 │      70         73       71
 3 │      51         45       40
>

Keywords: arrange, order