当前位置: 首页>>代码示例>>Python>>正文


Python operator.neg方法代码示例

本文整理汇总了Python中operator.neg方法的典型用法代码示例。如果您正苦于以下问题:Python operator.neg方法的具体用法?Python operator.neg怎么用?Python operator.neg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.neg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_numeric_methods_unary

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def _add_numeric_methods_unary(cls):
        """
        Add in numeric unary methods.
        """
        def _make_evaluate_unary(op, opstr):

            def _evaluate_numeric_unary(self):

                self._validate_for_numeric_unaryop(op, opstr)
                attrs = self._get_attributes_dict()
                attrs = self._maybe_update_attributes(attrs)
                return Index(op(self.values), **attrs)

            _evaluate_numeric_unary.__name__ = opstr
            return _evaluate_numeric_unary

        cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
        cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
        cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
        cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:base.py

示例2: _add_numeric_methods_unary

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def _add_numeric_methods_unary(cls):
        """ add in numeric unary methods """

        def _make_evaluate_unary(op, opstr):

            def _evaluate_numeric_unary(self):

                self._validate_for_numeric_unaryop(op, opstr)
                attrs = self._get_attributes_dict()
                attrs = self._maybe_update_attributes(attrs)
                return Index(op(self.values), **attrs)

            return _evaluate_numeric_unary

        cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
        cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
        cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
        cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:base.py

示例3: testNeg

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def testNeg(self):
        self.unaryCheck(operator.neg) 
开发者ID:myhdl,项目名称:myhdl,代码行数:4,代码来源:test_Signal.py

示例4: __neg__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def __neg__(self) -> bool:
        return operator.neg(self.size) 
开发者ID:tensortrade-org,项目名称:tensortrade,代码行数:4,代码来源:quantity.py

示例5: __neg__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def __neg__(self):
    return DeferredTensor.apply(operator.neg, self)

  # We need to override "both sides" of the below operators (e.g. both __add__
  # and __radd__) since other might not be a DeferredTensor (but will be casted
  # to one inside apply()). 
开发者ID:google-research,项目名称:tensorflow_constrained_optimization,代码行数:8,代码来源:deferred_tensor.py

示例6: test_unary_methods

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_unary_methods(self):
        array = np.array([-1, 0, 1, 2])
        array_like = ArrayLike(array)
        for op in [operator.neg,
                   operator.pos,
                   abs,
                   operator.invert]:
            _assert_equal_type_and_value(op(array_like), ArrayLike(op(array))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_mixins.py

示例7: test_exceptions

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_exceptions(self):
        a = np.ones((), dtype=np.bool_)[()]
        assert_raises(TypeError, operator.neg, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_scalarmath.py

示例8: test_result

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_result(self):
        types = np.typecodes['AllInteger'] + np.typecodes['AllFloat']
        with suppress_warnings() as sup:
            sup.filter(RuntimeWarning)
            for dt in types:
                a = np.ones((), dtype=dt)[()]
                assert_equal(operator.neg(a) + a, 0) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_scalarmath.py

示例9: _add_unary_ops

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def _add_unary_ops(cls):
        cls.__pos__ = cls._create_unary_method(operator.pos)
        cls.__neg__ = cls._create_unary_method(operator.neg)
        cls.__invert__ = cls._create_unary_method(operator.invert) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:sparse.py

示例10: eval_unary_operator

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def eval_unary_operator(node, env):
    operations = {
        '-': operator.neg,
        '!': operator.not_,
    }
    return operations[node.operator](eval_expression(node.right, env)) 
开发者ID:akrylysov,项目名称:abrvalg,代码行数:8,代码来源:interpreter.py

示例11: __neg__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def __neg__(self):
        ''' Return element-wise negative. '''
        return PhyDim2(*map(neg, self)) 
开发者ID:stanford-mast,项目名称:nn_dataflow,代码行数:5,代码来源:phy_dim2.py

示例12: __neg__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def __neg__(self):
    return NonStandardInteger(operator.neg(self.val)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:test_util.py

示例13: test_max

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_max(self):
        self.assertEqual(max('123123'), '3')
        self.assertEqual(max(1, 2, 3), 3)
        self.assertEqual(max((1, 2, 3, 1, 2, 3)), 3)
        self.assertEqual(max([1, 2, 3, 1, 2, 3]), 3)

        self.assertEqual(max(1, 2L, 3.0), 3.0)
        self.assertEqual(max(1L, 2.0, 3), 3)
        self.assertEqual(max(1.0, 2, 3L), 3L)

        for stmt in (
            "max(key=int)",                 # no args
            "max(1, key=int)",              # single arg not iterable
            "max(1, 2, keystone=int)",      # wrong keyword
            "max(1, 2, key=int, abc=int)",  # two many keywords
            "max(1, 2, key=1)",             # keyfunc is not callable
            ):
            try:
                exec(stmt) in globals()
            except TypeError:
                pass
            else:
                self.fail(stmt)

        self.assertEqual(max((1,), key=neg), 1)     # one elem iterable
        self.assertEqual(max((1,2), key=neg), 1)    # two elem iterable
        self.assertEqual(max(1, 2, key=neg), 1)     # two elems

        data = [random.randrange(200) for i in range(100)]
        keys = dict((elem, random.randrange(50)) for elem in data)
        f = keys.__getitem__
        self.assertEqual(max(data, key=f),
                         sorted(reversed(data), key=f)[-1]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_builtin.py

示例14: test_imap

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_imap(self):
        self.assertEqual(list(imap(operator.pow, range(3), range(1,7))),
                         [0**1, 1**2, 2**3])
        self.assertEqual(list(imap(None, 'abc', range(5))),
                         [('a',0),('b',1),('c',2)])
        self.assertEqual(list(imap(None, 'abc', count())),
                         [('a',0),('b',1),('c',2)])
        self.assertEqual(take(2,imap(None, 'abc', count())),
                         [('a',0),('b',1)])
        self.assertEqual(list(imap(operator.pow, [])), [])
        self.assertRaises(TypeError, imap)
        self.assertRaises(TypeError, imap, operator.neg)
        self.assertRaises(TypeError, imap(10, range(5)).next)
        self.assertRaises(ValueError, imap(errfunc, [4], [5]).next)
        self.assertRaises(TypeError, imap(onearg, [4], [5]).next) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_itertools.py

示例15: test_neg

# 需要导入模块: import operator [as 别名]
# 或者: from operator import neg [as 别名]
def test_neg(self):
        self.assertRaises(TypeError, operator.neg)
        self.assertRaises(TypeError, operator.neg, None)
        self.assertTrue(operator.neg(5) == -5)
        self.assertTrue(operator.neg(-5) == 5)
        self.assertTrue(operator.neg(0) == 0)
        self.assertTrue(operator.neg(-0) == 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_operator.py


注:本文中的operator.neg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。