當前位置: 首頁>>代碼示例>>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方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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=np.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:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:11,代碼來源:test_ufunc.py

示例2: 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:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_ufunc.py

示例3: 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:birforce,項目名稱:vnpy_crypto,代碼行數:44,代碼來源:test_mem_overlap.py


注:本文中的numpy.core.umath_tests.euclidean_pdist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。