【发布时间】:2019-10-31 20:45:00
【问题描述】:
我知道如何使用.where 根据here 之类的条件替换值,但我想知道如何用数字替换xarray 中的所有值。
提前致谢
【问题讨论】:
标签: python python-xarray
我知道如何使用.where 根据here 之类的条件替换值,但我想知道如何用数字替换xarray 中的所有值。
提前致谢
【问题讨论】:
标签: python python-xarray
根据文档here,您所要做的就是:
a = xr.DataArray(np.arange(16).reshape(4, 4), dims=['x', 'y'])
b = a.where(a > 5, other=5)
b = b.where(b < 5, other=5)
正如 r-beer 所建议的那样,一种直接的方法是:
a = a.where(a == 5, other=5)
【讨论】:
使用以下代码可能更直接:
a = xr.DataArray(np.arange(16).reshape(4, 4), dims=['x', 'y'])
c = a.where(a == 5, other=5)
【讨论】: