本文整理匯總了Python中numpy.core.umath_tests.matrix_multiply方法的典型用法代碼示例。如果您正苦於以下問題:Python umath_tests.matrix_multiply方法的具體用法?Python umath_tests.matrix_multiply怎麽用?Python umath_tests.matrix_multiply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.core.umath_tests
的用法示例。
在下文中一共展示了umath_tests.matrix_multiply方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_and_rot_model
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import matrix_multiply [as 別名]
def build_and_rot_model(a, e, s0, r):
"""
Build model and rotate according to the identified rotation matrix
"""
from numpy.core.umath_tests import matrix_multiply
r2 = Prob3dPose.upgrade_r(r.T).transpose((0, 2, 1))
mod = Prob3dPose.build_model(a, e, s0)
mod = matrix_multiply(r2, mod)
return mod
示例2: better_rec
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import matrix_multiply [as 別名]
def better_rec(self, w, model, s=1, weights=1, damp_z=1):
"""Quick switch to allow reconstruction at unknown scale
returns a,r and scale"""
from numpy.core.umath_tests import matrix_multiply
proj = matrix_multiply(self.cam[np.newaxis], model)
proj[:, :2] = (proj[:, :2] * s + w * weights) / (s + weights)
proj[:, 2] *= damp_z
out = matrix_multiply(self.cam.T[np.newaxis], proj)
return out
示例3: test_matrix_multiply_umath_empty
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import matrix_multiply [as 別名]
def test_matrix_multiply_umath_empty(self):
res = umt.matrix_multiply(np.ones((0, 10)), np.ones((10, 0)))
assert_array_equal(res, np.zeros((0, 0)))
res = umt.matrix_multiply(np.ones((10, 0)), np.ones((0, 10)))
assert_array_equal(res, np.zeros((10, 10)))
示例4: compare_matrix_multiply_results
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import matrix_multiply [as 別名]
def compare_matrix_multiply_results(self, tp):
d1 = np.array(np.random.rand(2, 3, 4), dtype=tp)
d2 = np.array(np.random.rand(2, 3, 4), dtype=tp)
msg = "matrix multiply on type %s" % d1.dtype.name
def permute_n(n):
if n == 1:
return ([0],)
ret = ()
base = permute_n(n-1)
for perm in base:
for i in range(n):
new = perm + [n-1]
new[n-1] = new[i]
new[i] = n-1
ret += (new,)
return ret
def slice_n(n):
if n == 0:
return ((),)
ret = ()
base = slice_n(n-1)
for sl in base:
ret += (sl+(slice(None),),)
ret += (sl+(slice(0, 1),),)
return ret
def broadcastable(s1, s2):
return s1 == s2 or s1 == 1 or s2 == 1
permute_3 = permute_n(3)
slice_3 = slice_n(3) + ((slice(None, None, -1),)*3,)
ref = True
for p1 in permute_3:
for p2 in permute_3:
for s1 in slice_3:
for s2 in slice_3:
a1 = d1.transpose(p1)[s1]
a2 = d2.transpose(p2)[s2]
ref = ref and a1.base is not None
ref = ref and a2.base is not None
if (a1.shape[-1] == a2.shape[-2] and
broadcastable(a1.shape[0], a2.shape[0])):
assert_array_almost_equal(
umt.matrix_multiply(a1, a2),
np.sum(a2[..., np.newaxis].swapaxes(-3, -1) *
a1[..., np.newaxis,:], axis=-1),
err_msg=msg + ' %s %s' % (str(a1.shape),
str(a2.shape)))
assert_equal(ref, True, err_msg="reference check")
示例5: compare_matrix_multiply_results
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import matrix_multiply [as 別名]
def compare_matrix_multiply_results(self, tp):
d1 = np.array(rand(2, 3, 4), dtype=tp)
d2 = np.array(rand(2, 3, 4), dtype=tp)
msg = "matrix multiply on type %s" % d1.dtype.name
def permute_n(n):
if n == 1:
return ([0],)
ret = ()
base = permute_n(n-1)
for perm in base:
for i in range(n):
new = perm + [n-1]
new[n-1] = new[i]
new[i] = n-1
ret += (new,)
return ret
def slice_n(n):
if n == 0:
return ((),)
ret = ()
base = slice_n(n-1)
for sl in base:
ret += (sl+(slice(None),),)
ret += (sl+(slice(0, 1),),)
return ret
def broadcastable(s1, s2):
return s1 == s2 or s1 == 1 or s2 == 1
permute_3 = permute_n(3)
slice_3 = slice_n(3) + ((slice(None, None, -1),)*3,)
ref = True
for p1 in permute_3:
for p2 in permute_3:
for s1 in slice_3:
for s2 in slice_3:
a1 = d1.transpose(p1)[s1]
a2 = d2.transpose(p2)[s2]
ref = ref and a1.base != None
ref = ref and a2.base != None
if broadcastable(a1.shape[-1], a2.shape[-2]) and \
broadcastable(a1.shape[0], a2.shape[0]):
assert_array_almost_equal(
umt.matrix_multiply(a1, a2),
np.sum(a2[..., np.newaxis].swapaxes(-3, -1) *
a1[..., np.newaxis,:], axis=-1),
err_msg = msg+' %s %s' % (str(a1.shape),
str(a2.shape)))
assert_equal(ref, True, err_msg="reference check")