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

时间:2018-10-03 15:35:05

标签: python arrays numpy indexing python-xarray

enter image description here

我使用了static getDerivedStateFromProps(props, state) { // correct console.log(props, state) // incorrect // console.log(this.props, this.state) // `this` can be used only for static methods // that are inside the class } ,但是出现了这个错误:

  

IndexError:不支持二维布尔索引。

1 个答案:

答案 0 :(得分:3)

我将使用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

,如有必要,它将自动移动到浮动。