broadcast_equals

UnitsAwareDataArray.broadcast_equals(other: Self) bool

Two DataArrays are broadcast equal if they are equal after broadcasting them against each other such that they have the same dimensions.

Parameters:

other (DataArray) – DataArray to compare to.

Returns:

equal – True if the two DataArrays are broadcast equal.

Return type:

bool

See also

DataArray.equals, DataArray.identical

Examples

>>> a = xr.DataArray([1, 2], dims="X")
>>> b = xr.DataArray([[1, 1], [2, 2]], dims=["X", "Y"])
>>> a
<xarray.DataArray (X: 2)> Size: 16B
array([1, 2])
Dimensions without coordinates: X
>>> b
<xarray.DataArray (X: 2, Y: 2)> Size: 32B
array([[1, 1],
       [2, 2]])
Dimensions without coordinates: X, Y

.equals returns True if two DataArrays have the same values, dimensions, and coordinates. .broadcast_equals returns True if the results of broadcasting two DataArrays against each other have the same values, dimensions, and coordinates.

>>> a.equals(b)
False
>>> a2, b2 = xr.broadcast(a, b)
>>> a2.equals(b2)
True
>>> a.broadcast_equals(b)
True