Skip to content

Mutliplication behavior #5186

Answered by keewis
e-dub asked this question in Q&A
Apr 18, 2021 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

if you look at the DataArray objects, the dimension names (arr.dims) are ("dim0", "dim1") for both objects. Since aXr and bXr have different shapes, the matrix multiplication fails. To fix this, you can add dimension names:

In [5]: aXr = xr.DataArray(a, dims=("a", "b"))
   ...: bXr = xr.DataArray(b, dims=("b", "c"))
   ...: aXr @ bXr
Out[5]: 
<xarray.DataArray (a: 10, c: 5)>
array([[10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10., 10., 10., 10.],
       [10., 10.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@e-dub
Comment options

@max-sixty
Comment options

@e-dub
Comment options

@max-sixty
Comment options

@e-dub
Comment options

Answer selected by andersy005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants