xarray.DataArray.dot#
- DataArray.dot(other, dim=None)[source]#
Perform dot product of two DataArrays along their shared dims.
Equivalent to taking taking tensordot over all shared dims.
- Parameters:
- Returns:
result (
DataArray) – Array resulting from the dot product over all shared dimensions.
See also
Notes
This method automatically aligns coordinates by their values (not their order). See Automatic alignment and
xarray.dot()for more details.Examples
>>> da_vals = np.arange(6 * 5 * 4).reshape((6, 5, 4)) >>> da = xr.DataArray(da_vals, dims=["x", "y", "z"]) >>> dm_vals = np.arange(4) >>> dm = xr.DataArray(dm_vals, dims=["z"])
>>> dm.dims ('z',)
>>> da.dims ('x', 'y', 'z')
>>> dot_result = da.dot(dm) >>> dot_result.dims ('x', 'y')
Coordinates are aligned by their values:
>>> x = xr.DataArray([1, 10], coords=[("foo", ["a", "b"])]) >>> y = xr.DataArray([2, 20], coords=[("foo", ["b", "a"])]) >>> x.dot(y) <xarray.DataArray ()> Size: 8B array(40)