Python numpy.ma.clump_masked()函数
numpy.ma.clump_masked()函数返回一个与一维数组的屏蔽团块相对应的片断列表。
语法: numpy.ma.clump_masked(arr)
参数 :
arr : [ndarray] 一个一维的屏蔽数组。
返回 : [slice列表] slices列表,Arr中每个连续区域的屏蔽元素都有一个。
代码#1:
# Python program explaining
# numpy.ma.clump_masked() 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_masked(arr)
print (gfg)
输出 :
[slice(0, 3, None), slice(6, 7, None)]
代码#2:
# Python program explaining
# numpy.ma.clump_masked() 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_masked(arr)
print (gfg)
输出 :
[slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]