当前位置: 首页>>代码示例>>Python>>正文


Python _umath_tests.euclidean_pdist方法代码示例

本文整理汇总了Python中numpy.core._umath_tests.euclidean_pdist方法的典型用法代码示例。如果您正苦于以下问题:Python _umath_tests.euclidean_pdist方法的具体用法?Python _umath_tests.euclidean_pdist怎么用?Python _umath_tests.euclidean_pdist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.core._umath_tests的用法示例。


在下文中一共展示了_umath_tests.euclidean_pdist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_euclidean_pdist

# 需要导入模块: from numpy.core import _umath_tests [as 别名]
# 或者: from numpy.core._umath_tests import euclidean_pdist [as 别名]
def test_euclidean_pdist(self):
        a = np.arange(12, dtype=float).reshape(4, 3)
        out = np.empty((a.shape[0] * (a.shape[0] - 1) // 2,), dtype=a.dtype)
        umt.euclidean_pdist(a, out)
        b = np.sqrt(np.sum((a[:, None] - a)**2, axis=-1))
        b = b[~np.tri(a.shape[0], dtype=bool)]
        assert_almost_equal(out, b)
        # An output array is required to determine p with signature (n,d)->(p)
        assert_raises(ValueError, umt.euclidean_pdist, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_ufunc.py

示例2: test_unary_gufunc_fuzz

# 需要导入模块: from numpy.core import _umath_tests [as 别名]
# 或者: from numpy.core._umath_tests import euclidean_pdist [as 别名]
def test_unary_gufunc_fuzz(self):
        shapes = [7, 13, 8, 21, 29, 32]
        gufunc = _umath_tests.euclidean_pdist

        rng = np.random.RandomState(1234)

        for ndim in range(2, 6):
            x = rng.rand(*shapes[:ndim])

            it = iter_random_view_pairs(x, same_steps=False, equal_size=True)

            min_count = 500 // (ndim + 1)**2

            overlapping = 0
            while overlapping < min_count:
                a, b = next(it)

                if min(a.shape[-2:]) < 2 or min(b.shape[-2:]) < 2 or a.shape[-1] < 2:
                    continue

                # Ensure the shapes are so that euclidean_pdist is happy
                if b.shape[-1] > b.shape[-2]:
                    b = b[...,0,:]
                else:
                    b = b[...,:,0]

                n = a.shape[-2]
                p = n * (n - 1) // 2
                if p <= b.shape[-1] and p > 0:
                    b = b[...,:p]
                else:
                    n = max(2, int(np.sqrt(b.shape[-1]))//2)
                    p = n * (n - 1) // 2
                    a = a[...,:n,:]
                    b = b[...,:p]

                # Call
                if np.shares_memory(a, b):
                    overlapping += 1

                with np.errstate(over='ignore', invalid='ignore'):
                    assert_copy_equivalent(gufunc, [a], out=b) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:44,代码来源:test_mem_overlap.py


注:本文中的numpy.core._umath_tests.euclidean_pdist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。