issues: 595813283
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
595813283 | MDU6SXNzdWU1OTU4MTMyODM= | 3946 | removing uneccessary dimension | 32069530 | open | 0 | 8 | 2020-04-07T11:57:36Z | 2022-05-02T23:07:33Z | NONE | Hi Everyone, Sometimes I generate DataArray which are invariant along a dimension. I was not able to find a function or a simple workaround to get rid of these dimensions (unless I already know their names). I would like to use something as a combination of "reduce" and "np.allclose". For the moment I use the equivalent code below which works but is not efficent. Could it be a candidate for a native efficent xarray function? This can drastically reduce memory usage if relevant. Thanks ```python ds = xr.DataArray([[1.,2.],[1.,2.]], dims=('x','y')) dims_to_remove=list() for d in ds.dims: if np.all(ds[{d:0}]==ds): dims_to_remove.append(d) ds = ds[dict.fromkeys(dims_to_remove,0)] ds = ds.squeeze() ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3946/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |