本文整理匯總了Python中numpy.ma.masked_less方法的典型用法代碼示例。如果您正苦於以下問題:Python ma.masked_less方法的具體用法?Python ma.masked_less怎麽用?Python ma.masked_less使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.ma
的用法示例。
在下文中一共展示了ma.masked_less方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: mask_to_limits
# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_less [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: operation
# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_less [as 別名]
def operation(self, opname, value):
"""Do operation on map values.
Do operations on the current map values. Valid operations are:
* 'elilt' or 'eliminatelessthan': Eliminate less than <value>
* 'elile' or 'eliminatelessequal': Eliminate less or equal than <value>
Args:
opname (str): Name of operation. See list above.
values (*): A scalar number (float) or a tuple of two floats,
dependent on operation opname.
Examples::
surf.operation('elilt', 200) # set all values < 200 as undef
"""
if opname in ("elilt", "eliminatelessthan"):
self._values = ma.masked_less(self._values, value)
elif opname in ("elile", "eliminatelessequal"):
self._values = ma.masked_less_equal(self._values, value)
else:
raise ValueError("Invalid operation name")
# ==================================================================================
# Operations restricted to inside/outside polygons
# ==================================================================================
示例3: _mask_to_limits
# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_less [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: _mask_to_limits
# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_less [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
示例5: _attvalues
# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_less [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