home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 610519628

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/3946#issuecomment-610519628 https://api.github.com/repos/pydata/xarray/issues/3946 610519628 MDEyOklzc3VlQ29tbWVudDYxMDUxOTYyOA== 35968931 2020-04-07T17:29:10Z 2020-04-07T17:32:59Z MEMBER

Hi @lanougue , thanks for the suggestion!

If I understand correctly, you want to check that all elements are close along one dimension, and if so, then select only one index from that dimension? That seems to me to be two consecutive operations, the first of which is a reduction, and the second is just .isel: ```python da = xr.DataArray([[1.,2.],[1.,2.]], dims=('x','y'))

def reduce_if_constant_along_dim(da, dim): first = da.isel(**{dim: 0}) constant_along_dim = (da == first).all(dim)

true = xr.full_like(da, fill_value=True).isel(**{dim: 0}, drop=True)
if constant_along_dim.equals(true):
    return da.isel(**{dim: 0}, drop=True)
else:
    return da

print(reduce_if_constant_along_dim(da, dim='x')) bash <xarray.DataArray (y: 2)> array([1., 2.]) ```

or are you imagining something that applies the above function to every dim, more like: ```python def drop_constant_dims(da): for dim in da.dims: da = reduce_if_constant_along_dim(da, dim) return da

print(drop_constant_dims(da)) bash <xarray.DataArray (y: 2)> array([1., 2.]) `` There might be a slightly neater way usingreduce` somehow though.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  595813283
Powered by Datasette · Queries took 0.903ms · About: xarray-datasette