numpy的 - 更换楠号 [英] Numpy - Replace a number with NaN
问题描述
我期待在numpy的与NaN的更换号码,我期待像numpy.nan_to_num功能,除了在反向。
的数量很可能会改变,因为不同的阵列处理,因为每个都可以具有一个唯一地定义NoDataValue。我看到有使用字典的人,但阵列都很大,充满了积极和消极的浮动。我怀疑这是不是有效的尝试所有这些加载到任何创建密钥。
我试着用以下和numpy的要求,我用任何()或全部()。我意识到我需要明智的重复元素,而是希望一个内置功能,可以实现这一点。
高清replaceNoData(scanBlock,NDV):
对于n,我历数(阵列):
如果我== NDV:
scanBlock [N] = numpy.nan
NDV是GDAL的任何数据值和数组是一个numpy的数组。
是一个蒙面的数组去也许是这样?
A [A == NDV] = numpy.nan
A == NDV会产生可以用作指数
一个布尔数组I am looking to replace a number with NaN in numpy and am looking for a function like numpy.nan_to_num, except in reverse.
The number is likely to change as different arrays are processed because each can have a uniquely define NoDataValue. I have see people using dictionaries, but the arrays are large and filled with both positive and negative floats. I suspect that it is not efficient to try to load all of these into anything to create keys.
I tried using the following and numpy requiring that I use any() or all(). I realize that I need to iterate element wise, but hope that a built-in function can achieve this.
def replaceNoData(scanBlock, NDV):
for n, i in enumerate(array):
if i == NDV:
scanBlock[n] = numpy.nan
NDV is GDAL's no data value and array is a numpy array.
Is a masked array the way to go perhaps?
A[A==NDV]=numpy.nan
A==NDV will produce a boolean array that can be used as an index for A
这篇关于numpy的 - 更换楠号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!