torch_ecg.utils.dicts_equal¶
- torch_ecg.utils.dicts_equal(d1: dict, d2: dict, allow_array_diff_types: bool = True) bool [source]¶
Determine if two dicts are equal.
- Parameters:
d1 (dict) – The two dicts to compare equality.
d2 (dict) – The two dicts to compare equality.
allow_array_diff_types (bool, default True) – Whether allow the equality of two arrays with different types, including list, tuple, numpy.ndarray, torch.Tensor, NOT including pandas.DataFrame, pandas.Series.
- Returns:
True if d1 equals d2, False otherwise.
- Return type:
Note
The existence of
ndarray
,Tensor
,DataFrame
andSeries
would probably cause errors when directly use the default__eq__
method ofdict
For example:>>> {"a": np.array([1,2])} == {"a": np.array([1,2])} ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Example
>>> d1 = {"a": pd.DataFrame([{"hehe":1,"haha":2}])[["haha","hehe"]]} >>> d2 = {"a": pd.DataFrame([{"hehe":1,"haha":2}])[["hehe","haha"]]} >>> dicts_equal(d1, d2) True