xarray.Dataset.broadcast_equals#
- Dataset.broadcast_equals(other)[source]#
Two Datasets are broadcast equal if they are equal after broadcasting all variables against each other.
For example, variables that are scalar in one dataset but non-scalar in the other dataset can still be broadcast equal if the the non-scalar variable is a constant.
Examples
# 2D array with shape (1, 3)
>>> data = np.array([[1, 2, 3]]) >>> a = xr.Dataset( ... {"variable_name": (("space", "time"), data)}, ... coords={"space": [0], "time": [0, 1, 2]}, ... ) >>> a <xarray.Dataset> Size: 56B Dimensions: (space: 1, time: 3) Coordinates: * space (space) int64 8B 0 * time (time) int64 24B 0 1 2 Data variables: variable_name (space, time) int64 24B 1 2 3
# 2D array with shape (3, 1)
>>> data = np.array([[1], [2], [3]]) >>> b = xr.Dataset( ... {"variable_name": (("time", "space"), data)}, ... coords={"time": [0, 1, 2], "space": [0]}, ... ) >>> b <xarray.Dataset> Size: 56B Dimensions: (time: 3, space: 1) Coordinates: * time (time) int64 24B 0 1 2 * space (space) int64 8B 0 Data variables: variable_name (time, space) int64 24B 1 2 3
.equals returns True if two Datasets have the same values, dimensions, and coordinates. .broadcast_equals returns True if the results of broadcasting two Datasets against each other have the same values, dimensions, and coordinates.
>>> a.equals(b) False
>>> a.broadcast_equals(b) True
>>> a2, b2 = xr.broadcast(a, b) >>> a2.equals(b2) True
See also
Dataset.equals
,Dataset.identical
,Dataset.broadcast