當前位置: 首頁>>代碼示例>>Python>>正文


Python numbers.Complex方法代碼示例

本文整理匯總了Python中numbers.Complex方法的典型用法代碼示例。如果您正苦於以下問題:Python numbers.Complex方法的具體用法?Python numbers.Complex怎麽用?Python numbers.Complex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numbers的用法示例。


在下文中一共展示了numbers.Complex方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __eq__

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def __eq__(a, b):
        """a == b"""
        if isinstance(b, numbers.Rational):
            return (a._numerator == b.numerator and
                    a._denominator == b.denominator)
        if isinstance(b, numbers.Complex) and b.imag == 0:
            b = b.real
        if isinstance(b, float):
            if math.isnan(b) or math.isinf(b):
                # comparisons with an infinity or nan should behave in
                # the same way for any finite a, so treat a as zero.
                return 0.0 == b
            else:
                return a == a.from_float(b)
        else:
            # Since a doesn't know how to compare with b, let's give b
            # a chance to compare itself with a.
            return NotImplemented 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:20,代碼來源:fractions.py

示例2: __eq__

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def __eq__(a, b):
        """a == b"""
        if isinstance(b, Rational):
            return (a._numerator == b.numerator and
                    a._denominator == b.denominator)
        if isinstance(b, numbers.Complex) and b.imag == 0:
            b = b.real
        if isinstance(b, float):
            if math.isnan(b) or math.isinf(b):
                # comparisons with an infinity or nan should behave in
                # the same way for any finite a, so treat a as zero.
                return 0.0 == b
            else:
                return a == a.from_float(b)
        else:
            # Since a doesn't know how to compare with b, let's give b
            # a chance to compare itself with a.
            return NotImplemented 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:20,代碼來源:fractions.py

示例3: as_str_any

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def as_str_any(value):
  """Converts to `str` as `str(value)`, but use `as_str` for `bytes`.

  Args:
    value: A object that can be converted to `str`.

  Returns:
    A `str` object.
  """
  if isinstance(value, bytes):
    return as_str(value)
  else:
    return str(value)


# Numpy 1.8 scalars don't inherit from numbers.Integral in Python 3, so we
# need to check them specifically.  The same goes from Real and Complex. 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:compat.py

示例4: __eq__

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def __eq__(a, b):
        """a == b"""
        if type(b) is int:
            return a._numerator == b and a._denominator == 1
        if isinstance(b, numbers.Rational):
            return (a._numerator == b.numerator and
                    a._denominator == b.denominator)
        if isinstance(b, numbers.Complex) and b.imag == 0:
            b = b.real
        if isinstance(b, float):
            if math.isnan(b) or math.isinf(b):
                # comparisons with an infinity or nan should behave in
                # the same way for any finite a, so treat a as zero.
                return 0.0 == b
            else:
                return a == a.from_float(b)
        else:
            # Since a doesn't know how to compare with b, let's give b
            # a chance to compare itself with a.
            return NotImplemented 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:fractions.py

示例5: _f90repr

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def _f90repr(self, value):
        """Convert primitive Python types to equivalent Fortran strings."""
        if isinstance(value, bool):
            return self._f90bool(value)
        elif isinstance(value, numbers.Integral):
            return self._f90int(value)
        elif isinstance(value, numbers.Real):
            return self._f90float(value)
        elif isinstance(value, numbers.Complex):
            return self._f90complex(value)
        elif isinstance(value, basestring):
            return self._f90str(value)
        elif value is None:
            return ''
        else:
            raise ValueError('Type {0} of {1} cannot be converted to a Fortran'
                             ' type.'.format(type(value), value)) 
開發者ID:marshallward,項目名稱:f90nml,代碼行數:19,代碼來源:namelist.py

示例6: complex_check

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def complex_check(*args, stacklevel=2):
    """Check if arguments are *complex numbers* (``complex``).

    Args:
        *args: Arguments to check.
        stacklevel (int): Stack level to fetch originated function name.

    Raises:
        ComplexError: If any of the arguments is **NOT** *complex number* (``complex``).

    """
    for var in args:
        if not isinstance(var, numbers.Complex):
            name = type(var).__name__
            func = inspect.stack()[stacklevel][3]
            raise ComplexError(f'Function {func} expected complex number, {name} got instead.') 
開發者ID:JarryShaw,項目名稱:PyPCAPKit,代碼行數:18,代碼來源:validations.py

示例7: path_to_str

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def path_to_str(path):
    """Returns the file system path representation of a `PathLike` object, else
    as it is.

    Args:
    path: An object that can be converted to path representation.

    Returns:
    A `str` object.
    """
    if hasattr(path, "__fspath__"):
        path = as_str_any(path.__fspath__())
    return path


# Numpy 1.8 scalars don't inherit from numbers.Integral in Python 3, so we
# need to check them specifically.  The same goes from Real and Complex. 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:19,代碼來源:__init__.py

示例8: set_input_value

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def set_input_value(self, name: str, value):
        # support lists here?
        if isinstance(value, (str, bool, numbers.Integral, numbers.Real, numbers.Complex)):
            self.__computation.set_input_value(name, value)
        if isinstance(value, dict) and value.get("object"):
            object = value.get("object")
            object_type = value.get("type")
            if object_type == "data_source":
                document_model = self.__computation.container.container.container.container
                display_item = document_model.get_display_item_for_data_item(object._data_item)
                display_data_channel = display_item.display_data_channel
                input_value = Symbolic.make_item(display_data_channel)
            else:
                input_value = Symbolic.make_item(object._item)
            self.__computation.set_input_item(name, input_value)
        elif hasattr(value, "_item"):
            input_value = Symbolic.make_item(value._item)
            self.__computation.set_input_item(name, input_value) 
開發者ID:nion-software,項目名稱:nionswift,代碼行數:20,代碼來源:Facade.py

示例9: test_abstract

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_abstract(self):
        assert_(issubclass(np.number, numbers.Number))

        assert_(issubclass(np.inexact, numbers.Complex))
        assert_(issubclass(np.complexfloating, numbers.Complex))
        assert_(issubclass(np.floating, numbers.Real))

        assert_(issubclass(np.integer, numbers.Integral))
        assert_(issubclass(np.signedinteger, numbers.Integral))
        assert_(issubclass(np.unsignedinteger, numbers.Integral)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py

示例10: test_complex

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_complex(self):
        for t in sctypes['complex']:
            assert_(isinstance(t(), numbers.Complex),
                    "{0} is not instance of Complex".format(t.__name__))
            assert_(issubclass(t, numbers.Complex),
                    "{0} is not subclass of Complex".format(t.__name__))
            assert_(not isinstance(t(), numbers.Real),
                    "{0} is instance of Real".format(t.__name__))
            assert_(not issubclass(t, numbers.Real),
                    "{0} is subclass of Real".format(t.__name__)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py

示例11: test_int

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_int(self):
        self.assertTrue(issubclass(int, Integral))
        self.assertTrue(issubclass(int, Complex))

        self.assertEqual(7, int(7).real)
        self.assertEqual(0, int(7).imag)
        self.assertEqual(7, int(7).conjugate())
        self.assertEqual(7, int(7).numerator)
        self.assertEqual(1, int(7).denominator) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_abstract_numbers.py

示例12: test_long

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_long(self):
        self.assertTrue(issubclass(long, Integral))
        self.assertTrue(issubclass(long, Complex))

        self.assertEqual(7, long(7).real)
        self.assertEqual(0, long(7).imag)
        self.assertEqual(7, long(7).conjugate())
        self.assertEqual(7, long(7).numerator)
        self.assertEqual(1, long(7).denominator) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_abstract_numbers.py

示例13: test_complex

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_complex(self):
        self.assertFalse(issubclass(complex, Real))
        self.assertTrue(issubclass(complex, Complex))

        c1, c2 = complex(3, 2), complex(4,1)
        # XXX: This is not ideal, but see the comment in math_trunc().
        self.assertRaises(AttributeError, math.trunc, c1)
        self.assertRaises(TypeError, float, c1)
        self.assertRaises(TypeError, int, c1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_abstract_numbers.py

示例14: test_complex

# 需要導入模塊: import numbers [as 別名]
# 或者: from numbers import Complex [as 別名]
def test_complex(self):
        for t in sctypes['complex']:
            assert_(isinstance(t(), numbers.Complex), 
                    "{0} is not instance of Complex".format(t.__name__))
            assert_(issubclass(t, numbers.Complex),
                    "{0} is not subclass of Complex".format(t.__name__))
            assert_(not isinstance(t(), numbers.Real), 
                    "{0} is instance of Real".format(t.__name__))
            assert_(not issubclass(t, numbers.Real),
                    "{0} is subclass of Real".format(t.__name__)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:12,代碼來源:test_abc.py


注:本文中的numbers.Complex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。