本文整理汇总了Python中MA.bitwise_or方法的典型用法代码示例。如果您正苦于以下问题:Python MA.bitwise_or方法的具体用法?Python MA.bitwise_or怎么用?Python MA.bitwise_or使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MA
的用法示例。
在下文中一共展示了MA.bitwise_or方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getMaskedArray
# 需要导入模块: import MA [as 别名]
# 或者: from MA import bitwise_or [as 别名]
def _getMaskedArray(self, var, flagVar=None, flagValues=(0, 1), missingValuesToTest=(-9999.0, -32767.0)):
"""
Returns a masked array that has the values only present where the flag
values are acceptable and the data itself is not missing.
"""
if flagVar:
flagFillValue = -1
flagGTValue = max(flagValues)
flagMaskWhereUnacceptable = MA.masked_greater(flagVar, flagGTValue).mask()
flagMaskWhereMissing = MA.masked_equal(flagVar, flagFillValue).mask()
flagMask = flagMaskWhereUnacceptable + flagMaskWhereMissing
for fv in missingValuesToTest:
if fv in MV.ravel(var):
print "Setting missing value for '%s' as: %s" % (var.id, fv)
varFillValue = fv
else:
varFillValue = missingValuesToTest[0]
if flagVar:
varMask = MA.masked_array(var, mask=MA.equal(var, varFillValue), fill_value=varFillValue).mask()
fullmask = MA.bitwise_or(varMask, flagMask)
maskedArray = MA.masked_array(var, mask=fullmask, fill_value=varFillValue)
else:
maskedArray = MA.masked_array(var, mask=MA.equal(var, varFillValue), fill_value=varFillValue)
# maskedArray=cdms.createVariable(maskedArray, id=var.id, fill_value=varFillValue)
# maskedArray.missing_value=varFillValue
return maskedArray
示例2: testOperators
# 需要导入模块: import MA [as 别名]
# 或者: from MA import bitwise_or [as 别名]
def testOperators (self):
"Test the operators +, -, *, /, %, ^, &, |"
x = MA.array([1.,2.,3.,4.,5.,6.])
y = MA.array([-1.,2.,0.,2.,-1, 3.])
assert eq(x + y, [0., 4., 3., 6., 4., 9.])
assert eq(x - y, [2., 0., 3., 2., 6., 3.])
assert eq(x * y, [-1., 4., 0., 8., -5., 18.])
assert eq(y / x, [-1, 1., 0., .5, -.2, .5])
assert eq(x**2, [1., 4., 9., 16., 25., 36.])
xc = MA.array([1.,2.,3.,4.,5.,6.])
xc += y
assert eq(xc, x + y)
xc = MA.array([1.,2.,3.,4.,5.,6.])
xc -= y
assert eq(xc, x - y)
yc = MA.array(y, copy=1)
yc /= x
assert eq ( yc, y / x)
xc = MA.array([1.,2.,3.,4.,5.,6.])
y1 = [-1.,2.,0.,2.,-1, 3.]
xc *= y1
assert eq(xc, x * y1)
assert eq (x + y, MA.add(x, y))
assert eq (x - y, MA.subtract(x, y))
assert eq (x * y, MA.multiply(x, y))
assert eq (y / x, MA.divide (y, x))
d = x / y
assert d[2] is MA.masked
assert (MA.array(1) / MA.array(0)) is MA.masked
assert eq (x**2, MA.power(x,2))
x = MA.array([1,2])
y = MA.zeros((2,))
assert eq (x%x, y)
assert eq (MA.remainder(x,x), y)
assert eq (x <<1, [2,4])
assert eq (MA.left_shift(x,1), [2,4])
assert eq (x >>1, [0,1])
assert eq (MA.right_shift(x,1), [0,1])
assert eq (x & 2, [0,2])
assert eq (MA.bitwise_and (x, 2), [0,2])
assert eq (x | 1, [1,3])
assert eq (MA.bitwise_or (x, 1), [1,3])
assert eq (x ^ 2, [3,0])
assert eq (MA.bitwise_xor(x,2), [3,0])
# x = divmod(MA.array([2,1]), MA.array([1,2]))
# assert eq (x[0], [2,0])
# assert eq (x[1], [0,1])
assert (4L*MA.arange(3)).typecode() == MA.PyObject