Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Zero to Nan in the array?

enter image description here

I used the temp[temp==0] = np.nan, but I got this Error:

IndexError: 2-dimensional boolean indexing is not supported.

like image 993
LEO Avatar asked Oct 30 '25 19:10

LEO


1 Answers

I'd use where, to avoid having to drop down to 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

and which will automatically move to floats if necessary.

like image 67
DSM Avatar answered Nov 01 '25 09:11

DSM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!