Generalized dot product for xarray objects. Like np.einsum
, but provides a simpler interface based on array dimension names.
Notes
We recommend installing the optional opt_einsum
package, or alternatively passing optimize=True
, which is passed through to np.einsum
, and works for most array backends.
Examples
>>> 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"]) >>> da_c = xr.DataArray(np.arange(2 * 3).reshape(2, 3), dims=["c", "d"])
>>> da_a <xarray.DataArray (a: 3, b: 2)> Size: 48B array([[0, 1], [2, 3], [4, 5]]) Dimensions without coordinates: a, b
>>> da_b <xarray.DataArray (a: 3, b: 2, c: 2)> Size: 96B array([[[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]], [[ 8, 9], [10, 11]]]) Dimensions without coordinates: a, b, c
>>> da_c <xarray.DataArray (c: 2, d: 3)> Size: 48B array([[0, 1, 2], [3, 4, 5]]) Dimensions without coordinates: c, d
>>> xr.dot(da_a, da_b, dim=["a", "b"]) <xarray.DataArray (c: 2)> Size: 16B array([110, 125]) Dimensions without coordinates: c
>>> xr.dot(da_a, da_b, dim=["a"]) <xarray.DataArray (b: 2, c: 2)> Size: 32B array([[40, 46], [70, 79]]) Dimensions without coordinates: b, c
>>> xr.dot(da_a, da_b, da_c, dim=["b", "c"]) <xarray.DataArray (a: 3, d: 3)> Size: 72B array([[ 9, 14, 19], [ 93, 150, 207], [273, 446, 619]]) Dimensions without coordinates: a, d
>>> xr.dot(da_a, da_b) <xarray.DataArray (c: 2)> Size: 16B array([110, 125]) Dimensions without coordinates: c
>>> xr.dot(da_a, da_b, dim=...) <xarray.DataArray ()> Size: 8B array(235)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4