'Setting to zero in Xarray
I have a variable with multiple dimensions concentration[time,lon, lat], I have found spurios negative concentration values at different times and at different lon and lattitude. I would like to set everything below 0 to zero, using xarray.
Is there straight forward way of accomplishing this?
Thanks!
Solution 1:[1]
You can apply numpy and scipy ufuncs, a.k.a. universal functions, which operate element-wise on a whole array, to an xarray object and the result will still be an xarray object. In this case:
da = np.maximum(da, 0)
See the xarray docs on computation for more description.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michael Delgado |
