当前位置: 首页>>代码示例>>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;未经允许,请勿转载。