本文整理汇总了Python中operator.inv方法的典型用法代码示例。如果您正苦于以下问题:Python operator.inv方法的具体用法?Python operator.inv怎么用?Python operator.inv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.inv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: p_unary_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def p_unary_operator(p):
'''unary_operator : '&'
| '*'
| '+'
| '-'
| '~'
| '!'
'''
# reduces to (op, op_str)
p[0] = ({
'+': operator.pos,
'-': operator.neg,
'~': operator.inv,
'!': operator.not_,
'&': 'AddressOfUnaryOperator',
'*': 'DereferenceUnaryOperator'}[p[1]], p[1])
示例2: test_normalInv
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def test_normalInv(self, g3):
layout, blades = g3, g3.blades
e1 = layout.blades['e1']
e2 = layout.blades['e2']
e3 = layout.blades['e3']
assert (2*e1).normalInv() == (0.5*e1)
with pytest.raises(ValueError):
(0*e1).normalInv() # divide by 0
with pytest.raises(ValueError):
(1 + e1 + e2).normalInv() # mixed even and odd grades
# produces garbage, but doesn't crash
(1 + e1 + e2).normalInv(check=False)
# check that not requiring normalInv works fine
assert (1 + e1 + e2).inv() == -1 + e1 + e2
示例3: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self):
"""Implement the ``~`` operator.
When used with SQL expressions, results in a
NOT operation, equivalent to
:func:`_expression.not_`, that is::
~a
is equivalent to::
from sqlalchemy import not_
not_(a)
"""
return self.operate(inv)
示例4: testInvert
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def testInvert(self):
self.unaryCheck(operator.inv)
示例5: test_logical_operators
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def test_logical_operators(self):
def _check_bin_op(op):
result = op(df1, df2)
expected = DataFrame(op(df1.values, df2.values), index=df1.index,
columns=df1.columns)
assert result.values.dtype == np.bool_
assert_frame_equal(result, expected)
def _check_unary_op(op):
result = op(df1)
expected = DataFrame(op(df1.values), index=df1.index,
columns=df1.columns)
assert result.values.dtype == np.bool_
assert_frame_equal(result, expected)
df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True},
'b': {'a': False, 'b': True, 'c': False,
'd': False, 'e': False},
'c': {'a': False, 'b': False, 'c': True,
'd': False, 'e': False},
'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True},
'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}}
df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False},
'b': {'a': False, 'b': True, 'c': False,
'd': False, 'e': False},
'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False},
'd': {'a': False, 'b': False, 'c': False,
'd': True, 'e': False},
'e': {'a': False, 'b': False, 'c': False,
'd': False, 'e': True}}
df1 = DataFrame(df1)
df2 = DataFrame(df2)
_check_bin_op(operator.and_)
_check_bin_op(operator.or_)
_check_bin_op(operator.xor)
_check_unary_op(operator.inv) # TODO: belongs elsewhere
示例6: test_invert
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def test_invert(self):
self.assertRaises(TypeError, operator.invert)
self.assertRaises(TypeError, operator.invert, None)
self.assertTrue(operator.inv(4) == -5)
示例7: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self):
arr = operator.inv(_values_from_object(self))
return self._wrap_array(arr, self.axes, copy=False)
示例8: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self):
arr = operator.inv(self.values)
return self._constructor(arr, self.index).__finalize__(self)
#----------------------------------------------------------------------
# unbox reductions
示例9: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self):
return self._uop(operator.inv)
示例10: __inv__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __inv__(self):
return self.apply_op1(operator.inv)
示例11: p_unary_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def p_unary_operator(self, p):
'''unary_operator : '+'
| '-'
| '~'
| '!'
'''
# reduces to (op, op_str)
p[0] = ({
'+': operator.pos,
'-': operator.neg,
'~': operator.inv,
'!': operator.not_}[p[1]], p[1])
示例12: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self):
return inv(self, graph=self.graph)
示例13: __invert__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def __invert__(self): return type(self)(self, operator.inv)
示例14: test_invert
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def test_invert(self):
self.failUnlessRaises(TypeError, operator.invert)
self.failUnlessRaises(TypeError, operator.invert, None)
self.failUnless(operator.inv(4) == -5)
示例15: test_inv_g4
# 需要导入模块: import operator [as 别名]
# 或者: from operator import inv [as 别名]
def test_inv_g4(self, g4):
'''
a numerical test for the inverse of a MV. truth was
generated by results of clifford v0.82
'''
layout, blades = g4, g4.blades
valA = np.array([
-0.3184271488037198 , -0.8751064635010213 , # noqa
-1.5011710376191947 , 1.7946332649746224 , # noqa
-0.8899576254164621 , -0.3297631748225678 , # noqa
0.04310366054166925, 1.3970365638677635 , # noqa
-1.545423393858595 , 1.7790215501876614 , # noqa
0.4785341530609175 , -1.32279679741638 , # noqa
0.5874769077573831 , -1.0227287710873676 , # noqa
1.779673249468527 , -1.5415648119743852 # noqa
])
valAinv = np.array([
0.06673424072253006 , -0.005709960252678998, # noqa
-0.10758540037163118 , 0.1805895938775471 , # noqa
0.13919236400967427 , 0.04123255613093294 , # noqa
-0.015395162562329407, -0.1388977308136247 , # noqa
-0.1462160646855434 , -0.1183453106997158 , # noqa
-0.06961956152268277 , 0.1396713851886765 , # noqa
-0.02572904638749348 , 0.02079613649197489 , # noqa
-0.06933660606043765 , -0.05436077710009021 # noqa
])
A = MultiVector(layout=layout, value=valA)
Ainv = MultiVector(layout=layout, value=valAinv)
np.testing.assert_almost_equal(A.inv().value, Ainv.value)