home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 275960531

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/60#issuecomment-275960531 https://api.github.com/repos/pydata/xarray/issues/60 275960531 MDEyOklzc3VlQ29tbWVudDI3NTk2MDUzMQ== 1217238 2017-01-30T00:54:09Z 2017-01-30T17:30:48Z MEMBER

See http://stackoverflow.com/questions/40179593/how-to-get-the-coordinates-of-the-maximum-in-xarray for examples of how to do this with the current version of xarray. @MaximilianR's answer using where is pretty clean, but maybe not the most efficient or exactly what we want. (I think it breaks in a few edge cases, such as if the max value appears multiple times, or the array is all NaN.)

@jcmgray Your proposal looks pretty close to me. But to handle higher dimension arrays, instead of take(y, indx), I think you need to NumPy style fancy indexing, y[indx,]. That doesn't work with dask, so you'll need to write a function function that uses dask.array.map_blocks when necessary.

I think something like the following would work: ```python def _index_from_1d_array(array, indices): return array[indices,]

def gufunc_idxmax(x, y, axis=None): # note: y is always a numpy.ndarray, because IndexVariable objects # always have their data loaded into memory indx = argmax(x, axis) func = functools.partial(_index_from_1d_array, y)

if isinstance(array, dask_array_type):
    import dask.array as da
    return da.map_blocks(func, indx, dtype=indx.dtype)
else:
    return func(indx)

```

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