📜  numpy.ma.notmasked_edges()函数| Python

📅  最后修改于: 2022-05-13 01:54:30.243000             🧑  作者: Mango

numpy.ma.notmasked_edges()函数| Python

numpy.ma.notmasked_edges()函数查找沿轴的第一个和最后一个未屏蔽值的索引。
如果所有值都被屏蔽,则返回 None。否则,返回两个元组的列表,分别对应第一个和最后一个未屏蔽值的索引。

代码#1:

# Python program explaining
# numpy.ma.notmasked_edges() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.arange(12).reshape((3, 4))
  
gfg = geek.ma.notmasked_edges(arr)
  
print (gfg)

输出 :

[ 0, 11]


代码#2:

# Python program explaining
# numpy.ma.notmasked_edges() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.arange(12).reshape((3, 4))
m = geek.zeros_like(arr)
m[1:, 1:] = 1
  
am = geek.ma.array(arr, mask = m)
  
gfg = geek.ma.notmasked_edges(am)
  
print (gfg)

输出 :

[0, 8]