本文整理匯總了Python中numpy.core.umath.multiply方法的典型用法代碼示例。如果您正苦於以下問題:Python umath.multiply方法的具體用法?Python umath.multiply怎麽用?Python umath.multiply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.core.umath
的用法示例。
在下文中一共展示了umath.multiply方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_wrap_with_iterable
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_wrap_with_iterable(self):
# test fix for bug #1026:
class with_wrap(np.ndarray):
__array_priority__ = 10
def __new__(cls):
return np.asarray(1).view(cls).copy()
def __array_wrap__(self, arr, context):
return arr.view(type(self))
a = with_wrap()
x = ncu.multiply(a, (1, 2, 3))
assert_(isinstance(x, with_wrap))
assert_array_equal(x, np.array((1, 2, 3)))
示例2: test_ufunc_override
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_ufunc_override(self):
# check override works even with instance with high priority.
class A(object):
def __array_ufunc__(self, func, method, *inputs, **kwargs):
return self, func, method, inputs, kwargs
class MyNDArray(np.ndarray):
__array_priority__ = 100
a = A()
b = np.array([1]).view(MyNDArray)
res0 = np.multiply(a, b)
res1 = np.multiply(b, b, out=a)
# self
assert_equal(res0[0], a)
assert_equal(res1[0], a)
assert_equal(res0[1], np.multiply)
assert_equal(res1[1], np.multiply)
assert_equal(res0[2], '__call__')
assert_equal(res1[2], '__call__')
assert_equal(res0[3], (a, b))
assert_equal(res1[3], (b, b))
assert_equal(res0[4], {})
assert_equal(res1[4], {'out': (a,)})
示例3: test_wrap_with_iterable
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_wrap_with_iterable(self):
# test fix for bug #1026:
class with_wrap(np.ndarray):
__array_priority__ = 10
def __new__(cls):
return np.asarray(1).view(cls).copy()
def __array_wrap__(self, arr, context):
return arr.view(type(self))
a = with_wrap()
x = ncu.multiply(a, (1, 2, 3))
self.assertTrue(isinstance(x, with_wrap))
assert_array_equal(x, np.array((1, 2, 3)))
示例4: test_ufunc_override
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_ufunc_override(self):
class A(object):
def __array_ufunc__(self, func, method, *inputs, **kwargs):
return self, func, method, inputs, kwargs
a = A()
b = np.matrix([1])
res0 = np.multiply(a, b)
res1 = np.multiply(b, b, out=a)
# self
assert_equal(res0[0], a)
assert_equal(res1[0], a)
assert_equal(res0[1], np.multiply)
assert_equal(res1[1], np.multiply)
assert_equal(res0[2], '__call__')
assert_equal(res1[2], '__call__')
assert_equal(res0[3], (a, b))
assert_equal(res1[3], (b, b))
assert_equal(res0[4], {})
assert_equal(res1[4], {'out': (a,)})
示例5: test_ufunc_override
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_ufunc_override(self):
class A(object):
def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):
return self, func, method, pos, inputs, kwargs
a = A()
b = np.matrix([1])
c = np.array([1])
res0 = np.multiply(a, b)
res1 = np.dot(a, b)
# self
assert_equal(res0[0], a)
assert_equal(res1[0], a)
assert_equal(res0[1], np.multiply)
assert_equal(res1[1], np.dot)
assert_equal(res0[2], '__call__')
assert_equal(res1[2], '__call__')
assert_equal(res0[3], 0)
assert_equal(res1[3], 0)
assert_equal(res0[4], (a, b))
assert_equal(res1[4], (a, b))
assert_equal(res0[5], {})
assert_equal(res1[5], {})
示例6: test_ufunc_override
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_ufunc_override(self):
# 2016-01-29: NUMPY_UFUNC_DISABLED
return
class A(object):
def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):
return self, func, method, pos, inputs, kwargs
a = A()
b = np.matrix([1])
res0 = np.multiply(a, b)
res1 = np.dot(a, b)
# self
assert_equal(res0[0], a)
assert_equal(res1[0], a)
assert_equal(res0[1], np.multiply)
assert_equal(res1[1], np.dot)
assert_equal(res0[2], '__call__')
assert_equal(res1[2], '__call__')
assert_equal(res0[3], 0)
assert_equal(res1[3], 0)
assert_equal(res0[4], (a, b))
assert_equal(res1[4], (a, b))
assert_equal(res0[5], {})
assert_equal(res1[5], {})
示例7: test_ufunc_override_out
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_ufunc_override_out(self):
# 2016-01-29: NUMPY_UFUNC_DISABLED
return
class A(object):
def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
return kwargs
class B(object):
def __numpy_ufunc__(self, ufunc, method, pos, inputs, **kwargs):
return kwargs
a = A()
b = B()
res0 = np.multiply(a, b, 'out_arg')
res1 = np.multiply(a, b, out='out_arg')
res2 = np.multiply(2, b, 'out_arg')
res3 = np.multiply(3, b, out='out_arg')
res4 = np.multiply(a, 4, 'out_arg')
res5 = np.multiply(a, 5, out='out_arg')
assert_equal(res0['out'], 'out_arg')
assert_equal(res1['out'], 'out_arg')
assert_equal(res2['out'], 'out_arg')
assert_equal(res3['out'], 'out_arg')
assert_equal(res4['out'], 'out_arg')
assert_equal(res5['out'], 'out_arg')
# ufuncs with multiple output modf and frexp.
res6 = np.modf(a, 'out0', 'out1')
res7 = np.frexp(a, 'out0', 'out1')
assert_equal(res6['out'][0], 'out0')
assert_equal(res6['out'][1], 'out1')
assert_equal(res7['out'][0], 'out0')
assert_equal(res7['out'][1], 'out1')
示例8: __mul__
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def __mul__(self, other):
"Return multiply(self, other)"
return multiply(self, other)
示例9: product
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def product (target, axis=None, dtype=None):
if axis is None:
target = ravel(target)
axis = 0
return multiply.reduce(target, axis, dtype)
示例10: test_wrap_with_iterable
# 需要導入模塊: from numpy.core import umath [as 別名]
# 或者: from numpy.core.umath import multiply [as 別名]
def test_wrap_with_iterable(self):
# test fix for bug #1026:
class with_wrap(np.ndarray):
__array_priority__ = 10
def __new__(cls):
return np.asarray(1).view(cls).copy()
def __array_wrap__(self, arr, context):
return arr.view(type(self))
a = with_wrap()
x = ncu.multiply(a, (1, 2, 3))
self.assertTrue(isinstance(x, with_wrap))
assert_array_equal(x, np.array((1, 2, 3)))