-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
MCVE Code Sample
import numpy as np
import xarray as xr
da_a = xr.DataArray(np.arange(3 * 2).reshape(3, 2), dims=['a', 'b'])
da_b = xr.DataArray(np.arange(3 * 2 * 2).reshape(3, 2, 2), dims=['a', 'b', 'c'])
xr.dot(da_a, da_b, dims=None)This sums over the common dimensions:
<xarray.DataArray (c: 2)>
array([110, 125])
Dimensions without coordinates: cTo sum over all dimensions:
xr.dot(da_a, da_b, dims=['a', 'b', 'c'])<xarray.DataArray (c: 2)>
array([110, 125])
Dimensions without coordinates: cProblem Description
xr.dot with dims=None currently sums over all the common dimensions. However, there are cases when a sum over all dimensions is desired. E.g. xr.dot(da_a, da_b, dims=['a', 'b', 'c']) is a a memory efficient way to compute (da_a * da_b).sum() (if a and b don't share the same dimensions). This is currently used in #2922 (example).
Therefore I suggest to allow xr.dot(da_a, da_b, dims=xr.ALL_DIMS) as shortcut to sum over all dimensions.
I assume there is no intent to change the behavior of xr.dot(..., dims=None)? (As it is a bit in contrast to other functions that are mostly applied over all dimensions.)
Output of xr.show_versions()
Details
# Paste the output here xr.show_versions() hereMetadata
Metadata
Assignees
Labels
No labels