简体   繁体   English

检查numpy数组是否被屏蔽

[英]Check if numpy array is masked or not

Is there an easy way to check if numpy array is masked or not? 有没有一种简单的方法来检查numpy数组是否被屏蔽?

Currently, I do the following to check if marr is masked or not: 目前,我执行以下操作来检查marr是否被屏蔽:

try:
   arr = marr.data
except:
   arr = marr

You can use the python function isinstance to check if an object is an instance of a class. 您可以使用python函数isinstance来检查对象是否是类的实例。

>>> isinstance(np.ma.array(np.arange(10)),np.ma.MaskedArray)
True
>>> isinstance(np.arange(10),np.ma.MaskedArray)
False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM