utils module¶
Utility functions.
-
utils.
map
(x, in_range, out_range)¶ Linearly map a value of x from an input range to an output range.
Note that the value is not constrained to the output range, nor does x need to be constrained to the input range
- Parameters
x (float) – the input value.
in_range ((float, float)) – tuple of the input range.
out_range ((float float)) – tuple of output range.
- Returns
the mapped value.
- Return type
float
-
utils.
sorted_by_key
(x, i, reverse=False)¶ For a list of lists, return list sorted by the ith component of list.
E.g. Sort on first entry of tuple:
> sorted_by_key([(1, 2), (5, 1]), 0) >>> [(1, 2), (5, 1)]
Sort on second entry of tuple:
> sorted_by_key([(1, 2), (5, 1)], 1) >>> [(5, 1), (1, 2)]
- Parameters
x (list[list/tuples]) –
i (int) – ith component of lists to sort from.
reverse (bool, optional) – reverse sorted list. The default is False.
- Returns
sorted list of lists/tuples.
- Return type
list[list/tuples]