Python 处理数组中的共同缺测问题

在大气和海洋科学领域,常常会遇到的一个问题是有两个数组,A,B,A和B在不同的位置均有缺测值的问题,而我们一般的情况下建模或者进行数据分析时候需要把A和B数组的缺测和非缺测的位置都设置为一致,基本的原理是当A和B在某个位置有数据缺测时候,则A和B均为缺测。处理这个问题的其中一种方法是基于np.isnan, np.logical_or, np.where相结合来解决。

以下是一个实际案例(7个数组):

ind1 =  np.isnan(obs_prec_fc24)
ind2 =  np.logical_or(np.isnan(prec_fc24), ind1)
ind1 =  ind2
ind2 =  np.logical_or(np.isnan(hgt_fc24), ind1)
ind1 =  ind2
ind2 =  np.logical_or(np.isnan(pw_fc24), ind1)
ind1 =  ind2
ind2 =  np.logical_or(np.isnan(omega_fc24), ind1)
ind1 =  ind2
ind2 =  np.logical_or(np.isnan(tem_fc24), ind1)
ind1 =  ind2
ind2 =  np.logical_or(np.isnan(rh_fc24), ind1)
ind1 =  ind2

obs_prec_f24= np.where(ind1, np.nan, obs_prec_fc24)
prec_f24    = np.where(ind1, np.nan, prec_fc24)
hgt_f24     = np.where(ind1, np.nan, hgt_fc24)
pw_f24      = np.where(ind1, np.nan, pw_fc24)
omega_f24   = np.where(ind1, np.nan, omega_fc24)
tem_f24     = np.where(ind1, np.nan, tem_fc24)
rh_f24      = np.where(ind1, np.nan, rh_fc24)

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值