我知道如何使用.where根据类似here的条件替换值,但是我想知道如何用数字替换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)

关于python - 如何在Python中用常量(例如5)替换xarray的所有值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58640323/

10-12 16:33
查看更多