gemseo.utils.comparisons module#
Data comparison tools.
- compare_dict_of_arrays(dict_of_arrays, other_dict_of_arrays, tolerance=0.0, nan_are_equal=False)[source]#
Check if two dictionaries of NumPy and/or SciPy sparse arrays are equal.
The dictionaries can be nested, in which case they are flattened. If the tolerance is set, then arrays are considered equal if
norm(dict_of_arrays[name] - other_dict_of_arrays[name]) /(1 + norm(other_dict_of_arrays[name])) <= tolerance
.- Parameters:
dict_of_arrays (Mapping[str, ndarray[Any, dtype[floating[Any]]] | coo_matrix | spmatrix | sparray] | Mapping[str, Mapping[str, ndarray[Any, dtype[floating[Any]]] | coo_matrix | spmatrix | sparray]]) -- A dictionary of NumPy arrays and/or SciPy sparse matrices.
other_dict_of_arrays (Mapping[str, ndarray[Any, dtype[floating[Any]]] | coo_matrix | spmatrix | sparray] | Mapping[str, Mapping[str, ndarray[Any, dtype[floating[Any]]] | coo_matrix | spmatrix | sparray]]) -- Another dictionary of NumPy arrays and/or SciPy sparse matrices.
tolerance (float) --
The relative tolerance. If 0.0, the array must be exactly equal.
By default it is set to 0.0.
nan_are_equal (bool) --
Whether to compare NaN's as equal.
By default it is set to False.
- Returns:
Whether the dictionaries are equal.
- Return type: