Skip to content

Tiling of xr.DataArray #6163

Answered by keewis
mliukis asked this question in Q&A
Jan 13, 2022 · 4 comments · 1 reply
Discussion options

You must be logged in to vote

I agree with @Illviljan that the same can be achieved using broadcasting:

In [11]: data = xr.DataArray(np.arange(0, 5), [("t", np.arange(0, 5))])
    ...: data
Out[11]: 
<xarray.DataArray (t: 5)>
array([0, 1, 2, 3, 4])
Coordinates:
  * t        (t) int64 0 1 2 3 4

In [12]: data * xr.DataArray(np.ones([5, 3]), dims=("x", "y"))
Out[12]: 
<xarray.DataArray (t: 5, x: 5, y: 3)>
array([[[0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.]],

       [[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]],

       [[2., 2., 2.],
        [2., 2., 2.],
        [2., 2., 2.],
        [2., 2., 2.],
        [2.

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@mliukis
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mliukis
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants