# Utilities¶

Various utility functions.

## API Reference¶

uncertainpy.utils.utility.contains_nan(values)[source]

Checks if None or numpy.nan exists in values. Returns True if any there are at least one occurrence of None or numpy.nan.

Parameters: values (array_like, list, number) – values where to check for occurrences of None or np.nan. Can be irregular and have any number of nested elements. True if values has at least one occurrence of None or numpy.nan. bool
uncertainpy.utils.utility.is_regular(values)[source]

Test if values is regular or not, meaning it has a varying length of nested elements.

Parameters: values (array_like, list, number) – values to check if it is regular or not, meaning it has a varying length of nested elements. True if the feature is regular or False if the feature is irregular. bool

Notes

Does not ignore numpy.nan, so [numpy.nan, [1, 2]] returns False.

uncertainpy.utils.utility.lengths(values)[source]

Get the lengths of a list and all its sublists.

Parameters: values (list) – List where we want to find the lengths of the list and all sublists. A list with the lengths of the list and all sublists. list
uncertainpy.utils.utility.none_to_nan(values)[source]

Converts None values in values to np.nan.

Parameters: values (array_like, list, number) – Values where to convert occurrences of None converted to np.nan. Can be irregular and have any number of nested elements. values – values with all occurrences of None converted to np.nan. array_like, list, number
uncertainpy.utils.utility.set_nan(values, index)[source]

Set the index of a arbitrarly nested list to nan

Parameters: values (array_like, list, number) – Values where to set index to numpy.nan. Can be irregular and have any number of nested elements. index (array_like, list, number) – Index where to set values to numpy.nan.