本文整理匯總了Python中numpy.core.umath_tests.inner1d方法的典型用法代碼示例。如果您正苦於以下問題:Python umath_tests.inner1d方法的具體用法?Python umath_tests.inner1d怎麽用?Python umath_tests.inner1d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.core.umath_tests
的用法示例。
在下文中一共展示了umath_tests.inner1d方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: HausdorffDist
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def HausdorffDist(A,B):
# Hausdorf Distance: Compute the Hausdorff distance between two point
# clouds.
# Let A and B be subsets of metric space (Z,dZ),
# The Hausdorff distance between A and B, denoted by dH(A,B),
# is defined by:
# dH(A,B) = max(h(A,B),h(B,A)),
# where h(A,B) = max(min(d(a,b))
# and d(a,b) is a L2 norm
# dist_H = hausdorff(A,B)
# A: First point sets (MxN, with M observations in N dimension)
# B: Second point sets (MxN, with M observations in N dimension)
# ** A and B may have different number of rows, but must have the same
# number of columns.
#
# Edward DongBo Cui; Stanford University; 06/17/2014
# Find pairwise distance
D_mat = np.sqrt(inner1d(A,A)[np.newaxis].T + inner1d(B,B)-2*(np.dot(A,B.T)))
# Find DH
dH = np.max(np.array([np.max(np.min(D_mat,axis=0)),np.max(np.min(D_mat,axis=1))]))
return(dH)
示例2: test_broadcast
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_broadcast(self):
msg = "broadcast"
a = np.arange(4).reshape((2, 1, 2))
b = np.arange(4).reshape((1, 2, 2))
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
msg = "extend & broadcast loop dimensions"
b = np.arange(4).reshape((2, 2))
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
# Broadcast in core dimensions should fail
a = np.arange(8).reshape((4, 2))
b = np.arange(4).reshape((4, 1))
assert_raises(ValueError, umt.inner1d, a, b)
# Extend core dimensions should fail
a = np.arange(8).reshape((4, 2))
b = np.array(7)
assert_raises(ValueError, umt.inner1d, a, b)
# Broadcast should fail
a = np.arange(2).reshape((2, 1, 1))
b = np.arange(3).reshape((3, 1, 1))
assert_raises(ValueError, umt.inner1d, a, b)
示例3: test_endian
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_endian(self):
msg = "big endian"
a = np.arange(6, dtype='>i4').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1),
err_msg=msg)
msg = "little endian"
a = np.arange(6, dtype='<i4').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1),
err_msg=msg)
# Output should always be native-endian
Ba = np.arange(1, dtype='>f8')
La = np.arange(1, dtype='<f8')
assert_equal((Ba+Ba).dtype, np.dtype('f8'))
assert_equal((Ba+La).dtype, np.dtype('f8'))
assert_equal((La+Ba).dtype, np.dtype('f8'))
assert_equal((La+La).dtype, np.dtype('f8'))
assert_equal(np.absolute(La).dtype, np.dtype('f8'))
assert_equal(np.absolute(Ba).dtype, np.dtype('f8'))
assert_equal(np.negative(La).dtype, np.dtype('f8'))
assert_equal(np.negative(Ba).dtype, np.dtype('f8'))
示例4: test_broadcast
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_broadcast(self):
msg = "broadcast"
a = np.arange(4).reshape((2, 1, 2))
b = np.arange(4).reshape((1, 2, 2))
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
msg = "extend & broadcast loop dimensions"
b = np.arange(4).reshape((2, 2))
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
msg = "broadcast in core dimensions"
a = np.arange(8).reshape((4, 2))
b = np.arange(4).reshape((4, 1))
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
msg = "extend & broadcast core and loop dimensions"
a = np.arange(8).reshape((4, 2))
b = np.array(7)
assert_array_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1), err_msg=msg)
msg = "broadcast should fail"
a = np.arange(2).reshape((2, 1, 1))
b = np.arange(3).reshape((3, 1, 1))
try:
ret = umt.inner1d(a, b)
assert_equal(ret, None, err_msg=msg)
except ValueError: None
示例5: test_endian
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_endian(self):
msg = "big endian"
a = np.arange(6, dtype='>i4').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1), err_msg=msg)
msg = "little endian"
a = np.arange(6, dtype='<i4').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1), err_msg=msg)
# Output should always be native-endian
Ba = np.arange(1, dtype='>f8')
La = np.arange(1, dtype='<f8')
assert_equal((Ba+Ba).dtype, np.dtype('f8'))
assert_equal((Ba+La).dtype, np.dtype('f8'))
assert_equal((La+Ba).dtype, np.dtype('f8'))
assert_equal((La+La).dtype, np.dtype('f8'))
assert_equal(np.absolute(La).dtype, np.dtype('f8'))
assert_equal(np.absolute(Ba).dtype, np.dtype('f8'))
assert_equal(np.negative(La).dtype, np.dtype('f8'))
assert_equal(np.negative(Ba).dtype, np.dtype('f8'))
示例6: ModHausdorffDist
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def ModHausdorffDist(A,B):
#This function computes the Modified Hausdorff Distance (MHD) which is
#proven to function better than the directed HD as per Dubuisson et al.
#in the following work:
#
#M. P. Dubuisson and A. K. Jain. A Modified Hausdorff distance for object
#matching. In ICPR94, pages A:566-568, Jerusalem, Israel, 1994.
#http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=576361
#
#The function computed the forward and reverse distances and outputs the
#maximum/minimum of both.
#Optionally, the function can return forward and reverse distance.
#
#Format for calling function:
#
#[MHD,FHD,RHD] = ModHausdorffDist(A,B);
#
#where
#MHD = Modified Hausdorff Distance.
#FHD = Forward Hausdorff Distance: minimum distance from all points of B
# to a point in A, averaged for all A
#RHD = Reverse Hausdorff Distance: minimum distance from all points of A
# to a point in B, averaged for all B
#A -> Point set 1, [row as observations, and col as dimensions]
#B -> Point set 2, [row as observations, and col as dimensions]
#
#No. of samples of each point set may be different but the dimension of
#the points must be the same.
#
#Edward DongBo Cui Stanford University; 06/17/2014
# Find pairwise distance
D_mat = np.sqrt(inner1d(A,A)[np.newaxis].T + inner1d(B,B)-2*(np.dot(A,B.T)))
# Calculating the forward HD: mean(min(each col))
FHD = np.mean(np.min(D_mat,axis=1))
# Calculating the reverse HD: mean(min(each row))
RHD = np.mean(np.min(D_mat,axis=0))
# Calculating mhd
MHD = np.max(np.array([FHD, RHD]))
return(MHD, FHD, RHD)
示例7: test_get_signature
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_get_signature(self):
assert_equal(umt.inner1d.signature, "(i),(i)->()")
示例8: test_inner1d
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_inner1d(self):
a = np.arange(6).reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1))
a = np.arange(6)
assert_array_equal(umt.inner1d(a, a), np.sum(a*a))
示例9: test_type_cast
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_type_cast(self):
msg = "type cast"
a = np.arange(6, dtype='short').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1),
err_msg=msg)
msg = "type cast on one argument"
a = np.arange(6).reshape((2, 3))
b = a + 0.1
assert_array_almost_equal(umt.inner1d(a, b), np.sum(a*b, axis=-1),
err_msg=msg)
示例10: test_output_argument
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_output_argument(self):
msg = "output argument"
a = np.arange(12).reshape((2, 3, 2))
b = np.arange(4).reshape((2, 1, 2)) + 1
c = np.zeros((2, 3), dtype='int')
umt.inner1d(a, b, c)
assert_array_equal(c, np.sum(a*b, axis=-1), err_msg=msg)
c[:] = -1
umt.inner1d(a, b, out=c)
assert_array_equal(c, np.sum(a*b, axis=-1), err_msg=msg)
msg = "output argument with type cast"
c = np.zeros((2, 3), dtype='int16')
umt.inner1d(a, b, c)
assert_array_equal(c, np.sum(a*b, axis=-1), err_msg=msg)
c[:] = -1
umt.inner1d(a, b, out=c)
assert_array_equal(c, np.sum(a*b, axis=-1), err_msg=msg)
msg = "output argument with incontiguous layout"
c = np.zeros((2, 3, 4), dtype='int16')
umt.inner1d(a, b, c[..., 0])
assert_array_equal(c[..., 0], np.sum(a*b, axis=-1), err_msg=msg)
c[:] = -1
umt.inner1d(a, b, out=c[..., 0])
assert_array_equal(c[..., 0], np.sum(a*b, axis=-1), err_msg=msg)
示例11: test_gufunc_override
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_gufunc_override(self):
# gufunc are just ufunc instances, but follow a different path,
# so check __array_ufunc__ overrides them properly.
class A(object):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return self, ufunc, method, inputs, kwargs
inner1d = ncu_tests.inner1d
a = A()
res = inner1d(a, a)
assert_equal(res[0], a)
assert_equal(res[1], inner1d)
assert_equal(res[2], '__call__')
assert_equal(res[3], (a, a))
assert_equal(res[4], {})
res = inner1d(1, 1, out=a)
assert_equal(res[0], a)
assert_equal(res[1], inner1d)
assert_equal(res[2], '__call__')
assert_equal(res[3], (1, 1))
assert_equal(res[4], {'out': (a,)})
# wrong number of arguments in the tuple is an error too.
assert_raises(TypeError, inner1d, a, out='two')
assert_raises(TypeError, inner1d, a, a, 'one', out='two')
assert_raises(TypeError, inner1d, a, a, 'one', 'two')
assert_raises(ValueError, inner1d, a, a, out=('one', 'two'))
assert_raises(ValueError, inner1d, a, a, out=())
示例12: test_type_cast
# 需要導入模塊: from numpy.core import umath_tests [as 別名]
# 或者: from numpy.core.umath_tests import inner1d [as 別名]
def test_type_cast(self):
msg = "type cast"
a = np.arange(6, dtype='short').reshape((2, 3))
assert_array_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1), err_msg=msg)
msg = "type cast on one argument"
a = np.arange(6).reshape((2, 3))
b = a+0.1
assert_array_almost_equal(umt.inner1d(a, a), np.sum(a*a, axis=-1),
err_msg=msg)