Generalized dot product for xarray objects. Like ``np.einsum``, but provides a simpler interface based on array dimension names. Parameters ---------- *arrays : DataArray or Variable Arrays to compute. dim : str, iterable of hashable, "..." or None, optional Whic
(
*arrays,
dim: Dims = None,
**kwargs: Any,
)
| 482 | |
| 483 | @deprecate_dims |
| 484 | def dot( |
| 485 | *arrays, |
| 486 | dim: Dims = None, |
| 487 | **kwargs: Any, |
| 488 | ): |
| 489 | """Generalized dot product for xarray objects. Like ``np.einsum``, but |
| 490 | provides a simpler interface based on array dimension names. |
| 491 | |
| 492 | Parameters |
| 493 | ---------- |
| 494 | *arrays : DataArray or Variable |
| 495 | Arrays to compute. |
| 496 | dim : str, iterable of hashable, "..." or None, optional |
| 497 | Which dimensions to sum over. Ellipsis ('...') sums over all dimensions. |
| 498 | If not specified, then all the common dimensions are summed over. |
| 499 | **kwargs : dict |
| 500 | Additional keyword arguments passed to ``numpy.einsum`` or |
| 501 | ``dask.array.einsum`` |
| 502 | |
| 503 | Returns |
| 504 | ------- |
| 505 | DataArray |
| 506 | |
| 507 | See Also |
| 508 | -------- |
| 509 | numpy.einsum |
| 510 | dask.array.einsum |
| 511 | opt_einsum.contract |
| 512 | |
| 513 | Notes |
| 514 | ----- |
| 515 | We recommend installing the optional ``opt_einsum`` package, or alternatively passing ``optimize=True``, |
| 516 | which is passed through to ``np.einsum``, and works for most array backends. |
| 517 | |
| 518 | **Coordinate Handling** |
| 519 | |
| 520 | Like all xarray operations, ``dot`` automatically aligns array coordinates. |
| 521 | Coordinates are aligned by their **values**, not their order. By default, xarray uses |
| 522 | an inner join, so only overlapping coordinate values are included. With the default |
| 523 | ``arithmetic_join="inner"``, ``dot(a, b)`` is mathematically equivalent to ``(a * b).sum()`` |
| 524 | over the specified dimensions. See :ref:`math automatic alignment` for more details. |
| 525 | |
| 526 | Examples |
| 527 | -------- |
| 528 | >>> da_a = xr.DataArray(np.arange(3 * 2).reshape(3, 2), dims=["a", "b"]) |
| 529 | >>> da_b = xr.DataArray(np.arange(3 * 2 * 2).reshape(3, 2, 2), dims=["a", "b", "c"]) |
| 530 | >>> da_c = xr.DataArray(np.arange(2 * 3).reshape(2, 3), dims=["c", "d"]) |
| 531 | |
| 532 | >>> da_a |
| 533 | <xarray.DataArray (a: 3, b: 2)> Size: 48B |
| 534 | array([[0, 1], |
| 535 | [2, 3], |
| 536 | [4, 5]]) |
| 537 | Dimensions without coordinates: a, b |
| 538 | |
| 539 | >>> da_b |
| 540 | <xarray.DataArray (a: 3, b: 2, c: 2)> Size: 96B |
| 541 | array([[[ 0, 1], |
no test coverage detected