Perform dot product of two DataArrays along their shared dims. Equivalent to taking taking tensordot over all shared dims. Parameters ---------- other : DataArray The other array with which the dot product is performed. dim : ..., str, Iterable o
(
self,
other: T_Xarray,
dim: Dims = None,
)
| 5161 | |
| 5162 | @deprecate_dims |
| 5163 | def dot( |
| 5164 | self, |
| 5165 | other: T_Xarray, |
| 5166 | dim: Dims = None, |
| 5167 | ) -> T_Xarray: |
| 5168 | """Perform dot product of two DataArrays along their shared dims. |
| 5169 | |
| 5170 | Equivalent to taking taking tensordot over all shared dims. |
| 5171 | |
| 5172 | Parameters |
| 5173 | ---------- |
| 5174 | other : DataArray |
| 5175 | The other array with which the dot product is performed. |
| 5176 | dim : ..., str, Iterable of Hashable or None, optional |
| 5177 | Which dimensions to sum over. Ellipsis (`...`) sums over all dimensions. |
| 5178 | If not specified, then all the common dimensions are summed over. |
| 5179 | |
| 5180 | Returns |
| 5181 | ------- |
| 5182 | result : DataArray |
| 5183 | Array resulting from the dot product over all shared dimensions. |
| 5184 | |
| 5185 | See Also |
| 5186 | -------- |
| 5187 | dot |
| 5188 | numpy.tensordot |
| 5189 | |
| 5190 | Notes |
| 5191 | ----- |
| 5192 | This method automatically aligns coordinates by their values (not their order). |
| 5193 | See :ref:`math automatic alignment` and :py:func:`xarray.dot` for more details. |
| 5194 | |
| 5195 | Examples |
| 5196 | -------- |
| 5197 | >>> da_vals = np.arange(6 * 5 * 4).reshape((6, 5, 4)) |
| 5198 | >>> da = xr.DataArray(da_vals, dims=["x", "y", "z"]) |
| 5199 | >>> dm_vals = np.arange(4) |
| 5200 | >>> dm = xr.DataArray(dm_vals, dims=["z"]) |
| 5201 | |
| 5202 | >>> dm.dims |
| 5203 | ('z',) |
| 5204 | |
| 5205 | >>> da.dims |
| 5206 | ('x', 'y', 'z') |
| 5207 | |
| 5208 | >>> dot_result = da.dot(dm) |
| 5209 | >>> dot_result.dims |
| 5210 | ('x', 'y') |
| 5211 | |
| 5212 | Coordinates are aligned by their values: |
| 5213 | |
| 5214 | >>> x = xr.DataArray([1, 10], coords=[("foo", ["a", "b"])]) |
| 5215 | >>> y = xr.DataArray([2, 20], coords=[("foo", ["b", "a"])]) |
| 5216 | >>> x.dot(y) |
| 5217 | <xarray.DataArray ()> Size: 8B |
| 5218 | array(40) |
| 5219 | |
| 5220 | """ |
no outgoing calls