home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 441343812

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/2568#issuecomment-441343812 https://api.github.com/repos/pydata/xarray/issues/2568 441343812 MDEyOklzc3VlQ29tbWVudDQ0MTM0MzgxMg== 1217238 2018-11-24T04:56:21Z 2018-11-24T04:56:33Z MEMBER

I would divide this into two steps: (1) write a function that does this on NumPy arrays and (2) apply it to xarray objects using apply_ufunc, e.g.,

```python import numpy as np import xarray as xr

def remap(array, mapping): return np.array([mapping[k] for k in array.ravel()]).reshape(array.shape)

ds = xr.Dataset({'test': ('t', [0, 1, 2])}) xr.apply_ufunc(remap, ds, kwargs=dict(mapping={0: 50, 1: 29, 2: 10})) outputs: <xarray.Dataset> Dimensions: (t: 3) Dimensions without coordinates: t Data variables: test (t) int64 50 29 10 ```

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