最佳答案
我会使用where
,以避免必须下拉到numpy:
In [35]: d
Out[35]:
<xarray.DataArray (dim_0: 2, dim_1: 3)>
array([[0, 1, 2],
[3, 4, 5]])
Dimensions without coordinates: dim_0, dim_1
In [36]: d.where(d != 0)
Out[36]:
<xarray.DataArray (dim_0: 2, dim_1: 3)>
array([[nan, 1., 2.],
[ 3., 4., 5.]])
Dimensions without coordinates: dim_0, dim_1
如有必要,它将自动移动到 float 。
关于python - 如何将数组中的零转换为Nan?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52630771/