home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 155293177

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/652#issuecomment-155293177 https://api.github.com/repos/pydata/xarray/issues/652 155293177 MDEyOklzc3VlQ29tbWVudDE1NTI5MzE3Nw== 1217238 2015-11-10T05:08:05Z 2015-11-10T05:08:05Z MEMBER

Yes, use the reduce method -- which should probably be called something more appropriately generic such as aggregate given that it doesn't only do reduces, e.g.,

``` In [5]: data_array = xray.DataArray(np.random.randn(3, 4, 5), dims=['x', 'y', 'z'])

In [14]: data_array.reduce(np.nanpercentile, q=95, dim=['x', 'y']) Out[14]: <xray.DataArray (z: 5)> array([ 1.79306097, 0.9788271 , 0.9385694 , 1.30198262, 1.78693993]) Coordinates: * z (z) int64 0 1 2 3 4 ```

To apply an operation along an axis that doesn't do an aggregation, you can use the get_axis_num, e.g.,

``` In [27]: xray.DataArray(np.argsort(data_array, axis=data_array.get_axis_num('x')), data_array.coords) Out[27]: <xray.DataArray (x: 3, y: 4, z: 5)> array([[[2, 1, 1, 2, 0], [0, 2, 2, 1, 0], [1, 1, 2, 1, 0], [2, 0, 0, 0, 0]],

   [[1, 2, 2, 0, 2],
    [2, 1, 1, 0, 1],
    [2, 0, 1, 0, 2],
    [1, 1, 2, 2, 1]],

   [[0, 0, 0, 1, 1],
    [1, 0, 0, 2, 2],
    [0, 2, 0, 2, 1],
    [0, 2, 1, 1, 2]]])

Coordinates: * x (x) int64 0 1 2 * y (y) int64 0 1 2 3 * z (z) int64 0 1 2 3 4 ```

We don't currently have a convenience method for the later but that might be good idea. I'm not entirely sure if it should be called DataArray.apply, but it could reuse maybe_wrap_array from Dataset.apply and add auto-conversion from dim to axis arguments

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