issue_comments: 610142267
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/3941#issuecomment-610142267 | https://api.github.com/repos/pydata/xarray/issues/3941 | 610142267 | MDEyOklzc3VlQ29tbWVudDYxMDE0MjI2Nw== | 30388627 | 2020-04-07T02:45:26Z | 2020-04-07T02:45:26Z | NONE | @dcherian Sorry for the misunderstanding. I tried again for the 3d array, it works well ;) ``` import xarray as xr import numpy as np x = 2 y = 4 z = 3 data = np.arange(xyz).reshape(z, x, y) input arraya = xr.DataArray(data, dims=['z', 'y', 'x']) start_index arraysindex = xr.DataArray(np.full_like(a[0, ...], 0), dims=['y', 'x']) end_index arrayeindex = xr.DataArray(np.full_like(a[0, ...], 1), dims=['y', 'x']) zindex = a.z.copy(data=np.arange(a.sizes["z"])) sub_z = (zindex >= sindex) & (zindex <= eindex) sum_a = a.where(sub_z).sum('z', keepdims=True) print(a) print(sum_a) ``` ``` <xarray.DataArray (z: 3, y: 2, x: 4)> array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]],
Dimensions without coordinates: z, y, x <xarray.DataArray (z: 1, y: 2, x: 4)> array([[[ 8., 10., 12., 14.], [16., 18., 20., 22.]]]) Dimensions without coordinates: z, y, x ``` |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
594900245 |