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


Python numpy.inner方法代码示例

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


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

示例1: random_projection

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def random_projection(X):

        data_demension = X.shape[1]

        new_data_demension = random.randint(2, data_demension)

        new_X = np.empty((data_demension, new_data_demension))

        minus_one = 0.1
        positive_one = 0.9

        for i in range(len(new_X)):
            for j in range(len(new_X[i])):
                rand = random.random()
                if rand < minus_one:
                    new_X[i][j] = -1.0
                elif rand >= positive_one:
                    new_X[i][j] = 1.0
                else:
                    new_X[i][j] = 0.0

        new_X = np.inner(X, new_X.T)

        return new_X 
开发者ID:fukuball,项目名称:fuku-ml,代码行数:26,代码来源:Utility.py

示例2: __init__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def __init__(self, y, x, height, width, angle):
        """
        A efficient tool to rotate multiple images in the same size.
        :author 申瑞珉 (Ruimin Shen)
        :param y: The y coordinate of rotation point.
        :param x: The x coordinate of rotation point.
        :param height: Image height.
        :param width: Image width.
        :param angle: Rotate angle.
        """
        self._mat = cv2.getRotationMatrix2D((x, y), angle, 1.0)
        r = np.abs(self._mat[0, :2])
        _height, _width = np.inner(r, [height, width]), np.inner(r, [width, height])
        fix_y, fix_x = _height / 2 - y, _width / 2 - x
        self._mat[:, 2] += [fix_x, fix_y]
        self._size = int(_width), int(_height) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:18,代码来源:augmentation.py

示例3: test_4

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_4(self):
        """
        Test of take, transpose, inner, outer products.

        """
        x = self.arange(24)
        y = np.arange(24)
        x[5:6] = self.masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert self.allequal(np.transpose(y, (2, 0, 1)), self.transpose(x, (2, 0, 1)))
        assert self.allequal(np.take(y, (2, 0, 1), 1), self.take(x, (2, 0, 1), 1))
        assert self.allequal(np.inner(self.filled(x, 0), self.filled(y, 0)),
                            self.inner(x, y))
        assert self.allequal(np.outer(self.filled(x, 0), self.filled(y, 0)),
                            self.outer(x, y))
        y = self.array(['abc', 1, 'def', 2, 3], object)
        y[2] = self.masked
        t = self.take(y, [0, 3, 4])
        assert t[0] == 'abc'
        assert t[1] == 2
        assert t[2] == 3 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:timer_comparison.py

示例4: test_testTakeTransposeInnerOuter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_testTakeTransposeInnerOuter(self):
        # Test of take, transpose, inner, outer products
        x = arange(24)
        y = np.arange(24)
        x[5:6] = masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert_(eq(np.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1))))
        assert_(eq(np.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1)))
        assert_(eq(np.inner(filled(x, 0), filled(y, 0)),
                   inner(x, y)))
        assert_(eq(np.outer(filled(x, 0), filled(y, 0)),
                   outer(x, y)))
        y = array(['abc', 1, 'def', 2, 3], object)
        y[2] = masked
        t = take(y, [0, 3, 4])
        assert_(t[0] == 'abc')
        assert_(t[1] == 2)
        assert_(t[2] == 3) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_old_ma.py

示例5: test_einsum_all_contig_non_contig_output

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_einsum_all_contig_non_contig_output(self):
        # Issue gh-5907, tests that the all contiguous special case
        # actually checks the contiguity of the output
        x = np.ones((5, 5))
        out = np.ones(10)[::2]
        correct_base = np.ones(10)
        correct_base[::2] = 5
        # Always worked (inner iteration is done with 0-stride):
        np.einsum('mi,mi,mi->m', x, x, x, out=out)
        assert_array_equal(out.base, correct_base)
        # Example 1:
        out = np.ones(10)[::2]
        np.einsum('im,im,im->m', x, x, x, out=out)
        assert_array_equal(out.base, correct_base)
        # Example 2, buffering causes x to be contiguous but
        # special cases do not catch the operation before:
        out = np.ones((2, 2, 2))[..., 0]
        correct_base = np.ones((2, 2, 2))
        correct_base[..., 0] = 2
        x = np.ones((2, 2), np.float32)
        np.einsum('ij,jk->ik', x, x, out=out)
        assert_array_equal(out.base, correct_base) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_einsum.py

示例6: word_sim_test

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def word_sim_test(filename, pos_vectors):
    delim = ','
    actual_sim_list, pred_sim_list = [], []
    missed = 0

    with open(filename, 'r') as pairs:
        for pair in pairs:
            w1, w2, actual_sim = pair.strip().split(delim)

            try:
                w1_vec = create_word_vector(w1, pos_vectors)
                w2_vec = create_word_vector(w2, pos_vectors)
                pred = float(np.inner(w1_vec, w2_vec))
                actual_sim_list.append(float(actual_sim))
                pred_sim_list.append(pred)

            except KeyError:
                missed += 1

    spearman, _ = st.spearmanr(actual_sim_list, pred_sim_list)
    pearson, _ = st.pearsonr(actual_sim_list, pred_sim_list)

    return spearman, pearson, missed 
开发者ID:dongjun-Lee,项目名称:kor2vec,代码行数:25,代码来源:similarity_test.py

示例7: test_lanczos_evolve

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_lanczos_evolve(n, N_cache, tol=5.e-14):
    # generate Hermitian test array
    leg = gen_random_legcharge(ch, n)
    H = npc.Array.from_func_square(rmat.GUE, leg) - npc.diag(1., leg)
    H_flat = H.to_ndarray()
    H_Op = H  # use `matvec` of the array
    qtotal = leg.to_qflat()[0]
    psi_init = npc.Array.from_func(np.random.random, [leg], qtotal=qtotal)
    psi_init /= npc.norm(psi_init)
    psi_init_flat = psi_init.to_ndarray()
    lanc = lanczos.LanczosEvolution(H_Op, psi_init, {'verbose': 1, 'N_cache': N_cache})
    for delta in [-0.1j, 0.1j, 1.j]:  #, 0.1, 1.]:
        psi_final_flat = expm(H_flat * delta).dot(psi_init_flat)
        psi_final, N = lanc.run(delta)
        ov = np.inner(psi_final.to_ndarray().conj(), psi_final_flat)
        ov /= np.linalg.norm(psi_final_flat)
        print("<psi1|psi1_flat>/norm=", ov)
        assert (abs(1. - abs(ov)) < tol) 
开发者ID:tenpy,项目名称:tenpy,代码行数:20,代码来源:test_lanczos.py

示例8: test_predict

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_predict(self):
        X_test = np.random.rand(10, 2)

        m, v = self.model.predict(X_test)

        assert len(m.shape) == 1
        assert m.shape[0] == X_test.shape[0]
        assert len(v.shape) == 1
        assert v.shape[0] == X_test.shape[0]

        m, v = self.model.predict(X_test, full_cov=True)

        assert len(m.shape) == 1
        assert m.shape[0] == X_test.shape[0]
        assert len(v.shape) == 2
        assert v.shape[0] == X_test.shape[0]
        assert v.shape[1] == X_test.shape[0]

        K_zz = self.kernel.get_value(X_test)
        K_zx = self.kernel.get_value(X_test, self.X)
        K_nz = self.kernel.get_value(self.X) + self.model.noise * np.eye(self.X.shape[0])
        inv = spla.inv(K_nz)
        K_zz_x = K_zz - np.dot(K_zx, np.inner(inv, K_zx))
        assert np.mean((K_zz_x - v) ** 2) < 10e-5 
开发者ID:automl,项目名称:RoBO,代码行数:26,代码来源:test_gaussian_process.py

示例9: test_TakeTransposeInnerOuter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_TakeTransposeInnerOuter(self):
        # Test of take, transpose, inner, outer products
        x = arange(24)
        y = np.arange(24)
        x[5:6] = masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert_equal(np.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1)))
        assert_equal(np.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1))
        assert_equal(np.inner(filled(x, 0), filled(y, 0)),
                     inner(x, y))
        assert_equal(np.outer(filled(x, 0), filled(y, 0)),
                     outer(x, y))
        y = array(['abc', 1, 'def', 2, 3], object)
        y[2] = masked
        t = take(y, [0, 3, 4])
        assert_(t[0] == 'abc')
        assert_(t[1] == 2)
        assert_(t[2] == 3) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:21,代码来源:test_core.py

示例10: test_einsum_misc

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_einsum_misc(self):
        # This call used to crash because of a bug in
        # PyArray_AssignZero
        a = np.ones((1, 2))
        b = np.ones((2, 2, 1))
        assert_equal(np.einsum('ij...,j...->i...', a, b), [[[2], [2]]])

        # The iterator had an issue with buffering this reduction
        a = np.ones((5, 12, 4, 2, 3), np.int64)
        b = np.ones((5, 12, 11), np.int64)
        assert_equal(np.einsum('ijklm,ijn,ijn->', a, b, b),
                        np.einsum('ijklm,ijn->', a, b))

        # Issue #2027, was a problem in the contiguous 3-argument
        # inner loop implementation
        a = np.arange(1, 3)
        b = np.arange(1, 5).reshape(2, 2)
        c = np.arange(1, 9).reshape(4, 2)
        assert_equal(np.einsum('x,yx,zx->xzy', a, b, c),
                    [[[1,  3], [3,  9], [5, 15], [7, 21]],
                    [[8, 16], [16, 32], [24, 48], [32, 64]]]) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:23,代码来源:test_einsum.py

示例11: fit

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def fit(self):
        """
        Fits the model by application of the Kalman filter

        Returns
        -------
        RecursiveLSResults
        """
        # Get the smoother results with an arbitrary measurement variance
        smoother_results = self.smooth(return_ssm=True)
        # Compute the MLE of sigma2 (see Harvey, 1989 equation 4.2.5)
        resid = smoother_results.standardized_forecasts_error[0]
        sigma2 = (np.inner(resid, resid) /
                  (self.nobs - self.loglikelihood_burn))

        # Now construct a results class, where the params are the final
        # estimates of the regression coefficients
        self['obs_cov', 0, 0] = sigma2
        return self.smooth() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:recursive_ls.py

示例12: test_4

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_4(self):
        "Test of take, transpose, inner, outer products"
        x = self.arange(24)
        y = np.arange(24)
        x[5:6] = self.masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert self.allequal(np.transpose(y, (2, 0, 1)), self.transpose(x, (2, 0, 1)))
        assert self.allequal(np.take(y, (2, 0, 1), 1), self.take(x, (2, 0, 1), 1))
        assert self.allequal(np.inner(self.filled(x, 0), self.filled(y, 0)),
                            self.inner(x, y))
        assert self.allequal(np.outer(self.filled(x, 0), self.filled(y, 0)),
                            self.outer(x, y))
        y = self.array(['abc', 1, 'def', 2, 3], object)
        y[2] = self.masked
        t = self.take(y, [0, 3, 4])
        assert t[0] == 'abc'
        assert t[1] == 2
        assert t[2] == 3
    #---------------------------------- 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:timer_comparison.py

示例13: test_testTakeTransposeInnerOuter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_testTakeTransposeInnerOuter(self):
        "Test of take, transpose, inner, outer products"
        x = arange(24)
        y = np.arange(24)
        x[5:6] = masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert_(eq(np.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1))))
        assert_(eq(np.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1)))
        assert_(eq(np.inner(filled(x, 0), filled(y, 0)),
                                inner(x, y)))
        assert_(eq(np.outer(filled(x, 0), filled(y, 0)),
                                outer(x, y)))
        y = array(['abc', 1, 'def', 2, 3], object)
        y[2] = masked
        t = take(y, [0, 3, 4])
        assert_(t[0] == 'abc')
        assert_(t[1] == 2)
        assert_(t[2] == 3) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_old_ma.py

示例14: test_TakeTransposeInnerOuter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def test_TakeTransposeInnerOuter(self):
        "Test of take, transpose, inner, outer products"
        x = arange(24)
        y = np.arange(24)
        x[5:6] = masked
        x = x.reshape(2, 3, 4)
        y = y.reshape(2, 3, 4)
        assert_equal(np.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1)))
        assert_equal(np.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1))
        assert_equal(np.inner(filled(x, 0), filled(y, 0)),
                            inner(x, y))
        assert_equal(np.outer(filled(x, 0), filled(y, 0)),
                            outer(x, y))
        y = array(['abc', 1, 'def', 2, 3], object)
        y[2] = masked
        t = take(y, [0, 3, 4])
        assert_(t[0] == 'abc')
        assert_(t[1] == 2)
        assert_(t[2] == 3) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_core.py

示例15: main

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import inner [as 别名]
def main(args_dict):
    text_embedder = FakeTextEmbedder()
    text_embedder.embed(["How are you?", "What is the time?", "What time it is?"])

    texts = ["Regenerácia vnútroblokov sídlisk mesta Brezno",
             "Územný plán mesta Brezno",
             "Oprava miestnych komunikácií v katastrálnom území mesta Brezno",
             "Kompostéry pre obec Kamenec pod Vtáčnikom",
             "Most cez potok Kamenec , Bardejov - mestská časť Dlhá Lúka",
             "Oprava miestnych komunikácií v katastrálnom území Trencin"]
    word2vec_embedder = Word2VecEmbedder(texts)
    embeddings = word2vec_embedder.embed(texts)
    print('Similarities:')
    for emb1, text1 in zip(embeddings, texts):
        for emb2, text2 in zip(embeddings, texts):
            similarity = np.inner(emb1, emb2) / (np.linalg.norm(emb1) * np.linalg.norm(emb2))
            print(similarity, text1, ' ----', text2) 
开发者ID:verejnedigital,项目名称:verejne.digital,代码行数:19,代码来源:embed.py


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