【问题标题】:get the data and the masked values as 0?将数据和掩码值设为 0?
【发布时间】:2015-08-02 12:47:44
【问题描述】:

我有一个掩码数组。 我可以通过array.data取回数据,但这不会通过掩码过滤数据。

我怎样才能得到数据,但是在有掩码的地方得到零。


这是我目前得到的:

 ary.data * (~ary.mask).astype(byte)

【问题讨论】:

    标签: python numpy mask


    【解决方案1】:

    使用numpy.ma.filled():

    import numpy as np
    m = np.ma.masked_greater(np.random.rand(10), 0.5)
    print np.ma.filled(m, 0)
    

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 2023-01-12
      • 2019-01-22
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多