Math Modules

Contents

pyavia.math.chain_mult Multiply start_val by each element in li in turn, producing a List of values the same length of li.
pyavia.math.is_number_seq Returns True if obj is of Sequence type and is not a string / bytes / bytearray.
pyavia.math.kind_atan2 Implementation of atan2 that allows any object as an argument provided it supports __div__ and __float__, allowing units-aware usage.
pyavia.math.kind_div Tries integer division of x/y before resorting to float.
pyavia.math.min_max Returns (min, max) of elements in iterable.
pyavia.math.monotonic Returns True if elements of iterable are monotonic otherwise false.
pyavia.math.strict_decrease Shorthand for monotonic(iterable, -1, strict=True, key=key).
pyavia.math.strict_increase Shorthand for monotonic(iterable, +1, strict=True, key=key).
pyavia.math.vectorise Applies function func to one or more *values that can be either scalar or vector.

Members

Useful mathematical functions, particularly if these are not available in NumPy.

pyavia.math.chain_mult(start_val, li: Sequence) → List

Multiply start_val by each element in li in turn, producing a List of values the same length of li. The starting value is not included.

Examples

>>> print(chain_mult(5.0, [2.0, 3.0, 0.5]))
[10.0, 30.0, 15.0]
pyavia.math.is_number_seq(obj) → bool

Returns True if obj is of Sequence type and is not a string / bytes / bytearray.

pyavia.math.kind_atan2(y, x) → float

Implementation of atan2 that allows any object as an argument provided it supports __div__ and __float__, allowing units-aware usage.

pyavia.math.kind_div(x, y) → Union[int, float]

Tries integer division of x/y before resorting to float. If integer division gives no remainder, returns this result otherwise it returns the float result. From https://stackoverflow.com/a/36637240.

pyavia.math.min_max(iterable, key=None)

Returns (min, max) of elements in iterable. Comparison provided using key if supplied.

pyavia.math.monotonic(iterable, dirn, strict=True, key=None)

Returns True if elements of iterable are monotonic otherwise false. For dirn >= 0 the sequence is strictly increasing i.e. \(x_{i+1} > x_i\), otherwise it is strictly decreasing i.e. \(x_i+1 < x_i\). If strict = False then equality is sufficient (i.e. >=, <= instead of >, <). Comparison provided using key if supplied.

pyavia.math.strict_decrease(iterable, key=None)

Shorthand for monotonic(iterable, -1, strict=True, key=key). Returns True i.f.f. all \(x_{i+1} < x_i\). Comparison provided using key if supplied.

pyavia.math.strict_increase(iterable, key=None)

Shorthand for monotonic(iterable, +1, strict=True, key=key). Returns True i.f.f. all \(x_{i+1} > x_i\). Comparison provided using key if supplied.

pyavia.math.vectorise(func: Callable, *values) → Union[list, Any]

Applies function func to one or more *values that can be either scalar or vector. The function must take the same number of arguments as there are *values:

  • If all values are numeric sequences, map() is used and a list is returned applying func to each of the value/s in turn. This applies even if the len() == 1 for the values.
  • If any value is not iterable: A scalar function and result is assumed.