本文整理汇总了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
示例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
示例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.
示例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
示例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))
示例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.')
示例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.
示例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)
示例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))
示例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__))
示例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)
示例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)
示例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)
示例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__))