Python numpy.ma.clump_unmasked()函数
numpy.ma.clump_unmasked()函数返回对应于一维数组中未被屏蔽的团块的切片列表。
语法: numpy.ma.clump_unmasked(arr)
参数 :
arr : [ndarray] 一个一维的屏蔽数组。
返回 : [slice列表] slice列表,a中每个未被掩盖的元素的连续区域都有一个slice。
代码#1:
# Python program explaining
# numpy.ma.clump_unmasked() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.masked_array(geek.arange(8))
arr[[0, 1, 2, 6]] = geek.ma.masked
gfg = geek.ma.clump_unmasked(arr)
print (gfg)
输出 :
[slice(3, 6, None), slice(7, 8, None)]
代码#2:
# Python program explaining
# numpy.ma.clump_unmasked() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.masked_array(geek.arange(10))
arr[[0, 1, 2, 6, 8, 9]] = geek.ma.masked
gfg = geek.ma.clump_unmasked(arr)
print (gfg)
输出 :
[slice(3, 6, None), slice(7, 8, None)]