本文整理汇总了Python中operator.truediv方法的典型用法代码示例。如果您正苦于以下问题:Python operator.truediv方法的具体用法?Python operator.truediv怎么用?Python operator.truediv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.truediv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _kspace_operation
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def _kspace_operation(image1, image2, padding, op, shape, axes):
"""Combine two images in k-space using a given `operator`
`image1` and `image2` are required to be `Fourier` objects and
`op` should be an operator (either `operator.mul` for a convolution
or `operator.truediv` for deconvolution). `shape` is the shape of the
output image (`Fourier` instance).
"""
if len(image1.shape) != len(image2.shape):
msg = "Both images must have the same number of axes, got {0} and {1}"
raise Exception(msg.format(len(image1.shape), len(image2.shape)))
fft_shape = _get_fft_shape(image1.image, image2.image, padding, axes)
convolved_fft = op(image1.fft(fft_shape, axes), image2.fft(fft_shape, axes))
# why is shape not image1.shape? images are never padded
convolved = Fourier.from_fft(convolved_fft, fft_shape, shape, axes)
return convolved
示例2: match_psfs
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def match_psfs(psf1, psf2, padding=3, axes=(-2, -1)):
"""Calculate the difference kernel between two psfs
Parameters
----------
psf1: `Fourier`
`Fourier` object representing the psf and it's FFT.
psf2: `Fourier`
`Fourier` object representing the psf and it's FFT.
padding: int
Additional padding to use when generating the FFT
to supress artifacts.
axes: tuple or None
Axes that contain the spatial information for the PSFs.
"""
if psf1.shape[0] < psf2.shape[0]:
shape = psf2.shape
else:
shape = psf1.shape
return _kspace_operation(psf1, psf2, padding, operator.truediv, shape, axes=axes)
示例3: test_truediv
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def test_truediv(Poly):
# true division is valid only if the denominator is a Number and
# not a python bool.
p1 = Poly([1,2,3])
p2 = p1 * 5
for stype in np.ScalarType:
if not issubclass(stype, Number) or issubclass(stype, bool):
continue
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in (int, long, float):
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in [complex]:
s = stype(5, 0)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for s in [tuple(), list(), dict(), bool(), np.array([1])]:
assert_raises(TypeError, op.truediv, p2, s)
assert_raises(TypeError, op.truediv, s, p2)
for ptype in classes:
assert_raises(TypeError, op.truediv, p2, ptype(1))
示例4: test_arith
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def test_arith(self):
self._test_op(self.panel, operator.add)
self._test_op(self.panel, operator.sub)
self._test_op(self.panel, operator.mul)
self._test_op(self.panel, operator.truediv)
self._test_op(self.panel, operator.floordiv)
self._test_op(self.panel, operator.pow)
self._test_op(self.panel, lambda x, y: y + x)
self._test_op(self.panel, lambda x, y: y - x)
self._test_op(self.panel, lambda x, y: y * x)
self._test_op(self.panel, lambda x, y: y / x)
self._test_op(self.panel, lambda x, y: y ** x)
self._test_op(self.panel, lambda x, y: x + y) # panel + 1
self._test_op(self.panel, lambda x, y: x - y) # panel - 1
self._test_op(self.panel, lambda x, y: x * y) # panel * 1
self._test_op(self.panel, lambda x, y: x / y) # panel / 1
self._test_op(self.panel, lambda x, y: x ** y) # panel ** 1
pytest.raises(Exception, self.panel.__add__,
self.panel['ItemA'])
示例5: test_binary_operators
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def test_binary_operators(self):
# skipping for now #####
import pytest
pytest.skip("skipping sparse binary operators test")
def _check_inplace_op(iop, op):
tmp = self.bseries.copy()
expected = op(tmp, self.bseries)
iop(tmp, self.bseries)
tm.assert_sp_series_equal(tmp, expected)
inplace_ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'pow']
for op in inplace_ops:
_check_inplace_op(getattr(operator, "i%s" % op),
getattr(operator, op))
示例6: _add_numeric_methods_binary
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def _add_numeric_methods_binary(cls):
"""
Add in numeric methods.
"""
cls.__add__ = _make_arithmetic_op(operator.add, cls)
cls.__radd__ = _make_arithmetic_op(ops.radd, cls)
cls.__sub__ = _make_arithmetic_op(operator.sub, cls)
cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls)
cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls)
cls.__pow__ = _make_arithmetic_op(operator.pow, cls)
cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls)
cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls)
if not compat.PY3:
cls.__div__ = _make_arithmetic_op(operator.div, cls)
cls.__rdiv__ = _make_arithmetic_op(ops.rdiv, cls)
# TODO: rmod? rdivmod?
cls.__mod__ = _make_arithmetic_op(operator.mod, cls)
cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls)
cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls)
cls.__divmod__ = _make_arithmetic_op(divmod, cls)
cls.__mul__ = _make_arithmetic_op(operator.mul, cls)
cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls)
示例7: __call__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def __call__(self, env):
"""Recursively evaluate an expression in Python space.
Parameters
----------
env : Scope
Returns
-------
object
The result of an evaluated expression.
"""
# handle truediv
if self.op == '/' and env.scope['truediv']:
self.func = op.truediv
# recurse over the left/right nodes
left = self.lhs(env)
right = self.rhs(env)
return self.func(left, right)
示例8: _gen_fill_zeros
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def _gen_fill_zeros(name):
"""
Find the appropriate fill value to use when filling in undefined values
in the results of the given operation caused by operating on
(generally dividing by) zero.
Parameters
----------
name : str
Returns
-------
fill_value : {None, np.nan, np.inf}
"""
name = name.strip('__')
if 'div' in name:
# truediv, floordiv, div, and reversed variants
fill_value = np.inf
elif 'mod' in name:
# mod, rmod
fill_value = np.nan
else:
fill_value = None
return fill_value
示例9: check_truediv
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def check_truediv(Poly):
# true division is valid only if the denominator is a Number and
# not a python bool.
p1 = Poly([1,2,3])
p2 = p1 * 5
for stype in np.ScalarType:
if not issubclass(stype, Number) or issubclass(stype, bool):
continue
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in (int, long, float):
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for stype in [complex]:
s = stype(5, 0)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
for s in [tuple(), list(), dict(), bool(), np.array([1])]:
assert_raises(TypeError, op.truediv, p2, s)
assert_raises(TypeError, op.truediv, s, p2)
for ptype in classes:
assert_raises(TypeError, op.truediv, p2, ptype(1))
示例10: test_arith
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def test_arith(self):
with catch_warnings(record=True):
self._test_op(self.panel, operator.add)
self._test_op(self.panel, operator.sub)
self._test_op(self.panel, operator.mul)
self._test_op(self.panel, operator.truediv)
self._test_op(self.panel, operator.floordiv)
self._test_op(self.panel, operator.pow)
self._test_op(self.panel, lambda x, y: y + x)
self._test_op(self.panel, lambda x, y: y - x)
self._test_op(self.panel, lambda x, y: y * x)
self._test_op(self.panel, lambda x, y: y / x)
self._test_op(self.panel, lambda x, y: y ** x)
self._test_op(self.panel, lambda x, y: x + y) # panel + 1
self._test_op(self.panel, lambda x, y: x - y) # panel - 1
self._test_op(self.panel, lambda x, y: x * y) # panel * 1
self._test_op(self.panel, lambda x, y: x / y) # panel / 1
self._test_op(self.panel, lambda x, y: x ** y) # panel ** 1
pytest.raises(Exception, self.panel.__add__,
self.panel['ItemA'])
示例11: testTrueDiv
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def testTrueDiv(self):
self.binaryCheck(operator.truediv, jmin=1)
示例12: __truediv__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def __truediv__(self, other):
return operator.truediv(self.__wrapped__, other)
示例13: __rtruediv__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def __rtruediv__(self, other):
return operator.truediv(other, self.__wrapped__)
示例14: __truediv__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def __truediv__(self, other):
assert type(other) in (int, long, float)
return Vector2(operator.truediv(self.x, other),
operator.truediv(self.y, other))
示例15: __rtruediv__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import truediv [as 别名]
def __rtruediv__(self, other):
assert type(other) in (int, long, float)
return Vector2(operator.truediv(other, self.x),
operator.truediv(other, self.y))