gpt4 book ai didi

python - 如何将数组中的零转换为Nan?

转载 作者:行者123 更新时间:2023-11-30 22:06:49 25 4
gpt4 key购买 nike

enter image description here

我使用了temp[temp==0] = np.nan,但我得到了这个错误:

IndexError: 2-dimensional boolean indexing is not supported.

最佳答案

我会使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com