本文整理汇总了Python中numpy.ma.masked_greater_equal方法的典型用法代码示例。如果您正苦于以下问题:Python ma.masked_greater_equal方法的具体用法?Python ma.masked_greater_equal怎么用?Python ma.masked_greater_equal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.masked_greater_equal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater_equal [as 别名]
def mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例2: _mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater_equal [as 别名]
def _mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例3: _mask_to_limits
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater_equal [as 别名]
def _mask_to_limits(a, limits, inclusive):
"""Mask an array for values outside of given limits.
This is primarily a utility function.
Parameters
----------
a : array
limits : (float or None, float or None)
A tuple consisting of the (lower limit, upper limit). Values in the
input array less than the lower limit or greater than the upper limit
will be masked out. None implies no limit.
inclusive : (bool, bool)
A tuple consisting of the (lower flag, upper flag). These flags
determine whether values exactly equal to lower or upper are allowed.
Returns
-------
A MaskedArray.
Raises
------
A ValueError if there are no values within the given limits.
"""
lower_limit, upper_limit = limits
lower_include, upper_include = inclusive
am = ma.MaskedArray(a)
if lower_limit is not None:
if lower_include:
am = ma.masked_less(am, lower_limit)
else:
am = ma.masked_less_equal(am, lower_limit)
if upper_limit is not None:
if upper_include:
am = ma.masked_greater(am, upper_limit)
else:
am = ma.masked_greater_equal(am, upper_limit)
if am.count() == 0:
raise ValueError("No array values within given limits")
return am
示例4: _attvalues
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_greater_equal [as 别名]
def _attvalues(attribute, stacked): # pylint: disable=too-many-branches
"""Attribute values computed in numpy.ma stack."""
if attribute == "max":
attvalues = ma.max(stacked, axis=2)
elif attribute == "min":
attvalues = ma.min(stacked, axis=2)
elif attribute == "rms":
attvalues = np.sqrt(ma.mean(np.square(stacked), axis=2))
elif attribute == "var":
attvalues = ma.var(stacked, axis=2)
elif attribute == "mean":
attvalues = ma.mean(stacked, axis=2)
elif attribute == "maxpos":
stacked = ma.masked_less(stacked, 0.0, copy=True)
attvalues = ma.max(stacked, axis=2)
elif attribute == "maxneg": # ~ minimum of negative values?
stacked = ma.masked_greater_equal(stacked, 0.0, copy=True)
attvalues = ma.min(stacked, axis=2)
elif attribute == "maxabs":
attvalues = ma.max(abs(stacked), axis=2)
elif attribute == "sumpos":
stacked = ma.masked_less(stacked, 0.0, copy=True)
attvalues = ma.sum(stacked, axis=2)
elif attribute == "sumneg":
stacked = ma.masked_greater_equal(stacked, 0.0, copy=True)
attvalues = ma.sum(stacked, axis=2)
elif attribute == "sumabs":
attvalues = ma.sum(abs(stacked), axis=2)
elif attribute == "meanabs":
attvalues = ma.mean(abs(stacked), axis=2)
elif attribute == "meanpos":
stacked = ma.masked_less(stacked, 0.0, copy=True)
attvalues = ma.mean(stacked, axis=2)
elif attribute == "meanneg":
stacked = ma.masked_greater_equal(stacked, 0.0, copy=True)
attvalues = ma.mean(stacked, axis=2)
else:
etxt = "Invalid attribute applied: {}".format(attribute)
raise ValueError(etxt)
if not attvalues.flags["C_CONTIGUOUS"]:
mask = ma.getmaskarray(attvalues)
mask = np.asanyarray(mask, order="C")
attvalues = np.asanyarray(attvalues, order="C")
attvalues = ma.array(attvalues, mask=mask, order="C")
return attvalues