當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。