python将缺失值用0代替_平滑而不使用零填充缺失值

此问题与以下问题和答案有关(免责声明:来自我):

它可以按如下方式转移到您的案例中:import numpy as np

import healpy as hp

nside = 128

npix = hp.nside2npix(nside)

# using random numbers here to see the actual smoothing

arr = np.random.rand(npix)

mask = np.zeros(npix, dtype=bool)

mask[:mask.size//2] = True

def masked_smoothing(U, rad=5.0):

V=U.copy()

V[U!=U]=0

VV=hp.smoothing(V, fwhm=np.radians(rad))

W=0*U.copy()+1

W[U!=U]=0

WW=hp.smoothing(W, fwhm=np.radians(rad))

return VV/WW

# setting array to np.nan to exclude the pixels in the smoothing

arr[~mask] = np.nan

arr_sm = masked_smoothing(arr)

arr_sm[~mask] = hp.UNSEEN

hp.mollview(arr, title='Input array')

hp.mollview(arr_sm, title='Smoothed array')

P9Wtd.pngxorG8.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值