Concise way to filter data in xarray
I need to apply a very simple 'match statement' to the values in an xarray array: Where the value > 0, make 2 Where the value == 0, make 0 Where the value is NaN , make NaN Here's my current solution. I'm using NaN s, .fillna , & type coercion in lieu of 2d indexing. valid = date_by_items.notnull() positive = date_by_items > 0 positive = positive * 2 result = positive.fillna(0.).where(valid) result This changes this: In [20]: date_by_items = xr.DataArray(np.asarray((list(range(3)) * 10)).reshape(6,5), dims=('date','item')) ...: date_by_items ...: Out[20]: <xarray.DataArray (date: 6, item: 5)>