Skip to content

einsum for xarray #1951

Closed
Closed
@fujiisoup

Description

@fujiisoup

Code Sample, a copy-pastable example if possible

I sometimes want to make more flexible dot product of two data arrays,
where we sum up along a part of common dimensions.

# Your code here
da_vals = np.arange(6 * 5 * 4).reshape((6, 5, 4))
da = DataArray(da_vals, dims=['x', 'y', 'z'])
dm_vals = np.arange(6 * 4).reshape((6, 4))
dm = DataArray(dm_vals, dims=['x', 'z'])

# I want something like this
da.dot(dm, 'z')  # -> dimensions of the output array: ['x', 'y']

It's an intermediate path of np.matmul and np.tensordot.

Is this feature sufficiently universal?

EDIT:
I just noticed dask does not have einsum yet (dask/dask#732).
We maybe need to wait or decide to support only numpy arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions