lib5c.util.mathematics module

Module for mathematical utility functions.

lib5c.util.mathematics.gmean(array, pseudocount=1, axis=None)[source]

Compute the geometric mean of an input array.

Parameters:
  • array (np.ndarray) – The array to take the geometric mean over.
  • pseudocount (float) – The pseudocount to add to the elements of array before logging.
  • axis (int, optional) – The axis to compute the mean over.
Returns:

The geometric mean.

Return type:

float

lib5c.util.mathematics.symmetrize(array, source='lower')[source]

Symmetrizes a square array using its lower triangular entries.

Parameters:
  • array (np.ndarray) – Array to symmetrize. Must be square.
  • source ({'lower', 'upper'}) – What triangle of the matrix to symmetrize with.
Returns:

A symmetrized copy of array.

Return type:

np.ndarray

lib5c.util.mathematics.zero_nans(array)[source]

Zeros all the nan’s in an array. Useful for cases where functions like np.nansum() are not available (e.g., scipy.ndimage.convolve()).

Parameters:array (np.ndarray) – The array to zero nan’s in.
Returns:Copy of array with all nan’s set to zero.
Return type:np.ndarray