issues: 403350812
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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 403350812 | MDU6SXNzdWU0MDMzNTA4MTI= | 2711 | Substituting values based on condition | 15331990 | closed | 0 | 2 | 2019-01-25T22:03:10Z | 2019-01-26T03:22:07Z | 2019-01-26T03:22:07Z | CONTRIBUTOR | Is there a more intuitive, built-in way of substituting values based on the conditions without having to flip every logic operator? ``` import xarray as xr ds = xr.tutorial.open_dataset('air_temperature') ds['text'] = (('time', 'lat', 'lon'), np.zeros_like(ds['air'].values).astype(str)) ds['text'] = ds['text'].where(ds['air'] < 273, 'above freezing') ds['text'] = ds['text'].where(ds['air'] > 273, 'below freezing') ds['text'] = ds['text'].where(ds['air'] != 273, 'freezing') ds.hvplot('lon', 'lat', z='air', hover_cols=['text']).opts(color_levels=[200, 273, 300]) ``` The numpy equivalent (also seems faster by 2x) ``` above_freezing = np.where(ds['air'].values > 273) ds['text'].data[above_freezing] = 'above_freezing' below_freezing = np.where(ds['air'].values < 273) ds['text'].data[below_freezing] = 'below_freezing' freezing = np.where(ds['air'].values == 273) ds['text'].data[freezing] = 'freezing' ```
|
{
"url": "https://api.github.com/repos/pydata/xarray/issues/2711/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} |
completed | 13221727 | issue |
