當前位置: 首頁>>代碼示例>>Python>>正文


Python matlib.repmat方法代碼示例

本文整理匯總了Python中numpy.matlib.repmat方法的典型用法代碼示例。如果您正苦於以下問題:Python matlib.repmat方法的具體用法?Python matlib.repmat怎麽用?Python matlib.repmat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.matlib的用法示例。


在下文中一共展示了matlib.repmat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_fexpand

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def test_fexpand(self):
        # test odd input
        res = np.random.rand(11)
        X = ft.freduce(np.fft.fft(res))
        R = np.real(np.fft.ifft(ft.fexpand(X, 11)))
        self.assertTrue(np.all((res - R) < 1e-6))
        # test even input
        res = np.random.rand(12)
        X = ft.freduce(np.fft.fft(res))
        R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
        self.assertTrue(np.all((res - R) < 1e-6))
        # test with a 2 dimensional input along last dimension
        res = np.random.rand(2, 12)
        X = ft.freduce(np.fft.fft(res))
        R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
        self.assertTrue(np.all((res - R) < 1e-6))
        # test with a 3 dimensional input along last dimension
        res = np.random.rand(3, 5, 12)
        X = ft.freduce(np.fft.fft(res))
        R = np.real(np.fft.ifft(ft.fexpand(X, 12)))
        self.assertTrue(np.all((res - R) < 1e-6))
        # test with 2 dimensional input along first dimension
        fs = np.transpose(mat.repmat(ft.fscale(500, 0.001, one_sided=True), 4, 1))
        self.assertTrue(ft.fexpand(fs, 500, axis=0).shape == (500, 4)) 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:26,代碼來源:test_dsp.py

示例2: test_filter_lp_hp

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def test_filter_lp_hp(self):
        # test 1D time serie: subtracting lp filter removes DC
        ts1 = np.random.rand(500)
        out1 = ft.lp(ts1, 1, [.1, .2])
        self.assertTrue(np.mean(ts1 - out1) < 0.001)
        # test 2D case along the last dimension
        ts = mat.repmat(ts1, 11, 1)
        out = ft.lp(ts, 1, [.1, .2])
        self.assertTrue(np.allclose(out, out1))
        # test 2D case along the first dimension
        ts = mat.repmat(ts1[:, np.newaxis], 1, 11)
        out = ft.lp(ts, 1, [.1, .2], axis=0)
        self.assertTrue(np.allclose(np.transpose(out), out1))
        # test 1D time serie: subtracting lp filter removes DC
        out2 = ft.hp(ts1, 1, [.1, .2])
        self.assertTrue(np.allclose(out1, ts1 - out2)) 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:18,代碼來源:test_dsp.py

示例3: sample_inside_polytope

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def sample_inside_polytope(x, a, b):
    """
    for a set of samples x = [x_1,..,x_k]^T
    check sample_wise
        Ax_i \leq b , i=1,..,k

    x: k x n np.ndarray[float]
        The samples (k samples of dimensionality n)
    a: m x n np.ndarray[float]
        the matrix of the linear inequality
    b: m x 1 np.ndarray[float]
        the vector of the linear inequality

    """
    k, _ = x.shape

    c = np.dot(a, x.T) - repmat(b, 1, k)

    return np.all(c < 0, axis=0).squeeze() 
開發者ID:befelix,項目名稱:safe-exploration,代碼行數:21,代碼來源:utils.py

示例4: _create_accum_list_labeled

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def _create_accum_list_labeled(self, shortest_paths, maxpath,
                                   labels_t, numlabels):
        """
        Construct accumulation array matrix for one dataset
        containing labaled graph data.
        """
        res = lil_matrix(
            np.zeros((len(shortest_paths),
                      (maxpath + 1) * numlabels * (numlabels + 1) / 2)))
        for i, s in enumerate(shortest_paths):
            labels = labels_t[i]
            labels_aux = matlib.repmat(labels, 1, len(labels))
            min_lab = np.minimum(labels_aux.T, labels_aux)
            max_lab = np.maximum(labels_aux.T, labels_aux)
            subsetter = np.triu(~(np.isinf(s)))
            min_lab = min_lab[subsetter]
            max_lab = max_lab[subsetter]
            ind = s[subsetter] * numlabels * (numlabels + 1) / 2 + \
                    (min_lab - 1) * (2*numlabels + 2 - min_lab) / 2 + \
                    max_lab - min_lab
            accum = np.zeros((maxpath + 1) * numlabels * (numlabels + 1) / 2)
            accum[:ind.max() + 1] += np.bincount(ind.astype(int))
            res[i] = lil_matrix(accum)
        return res 
開發者ID:gmum,項目名稱:pykernels,代碼行數:26,代碼來源:shortestpath.py

示例5: sqdist

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def sqdist(a, b):
    """calculate the square distance between a, b
    Arguments
    ---------
        a: 'np.ndarray'
            A matrix with :math:`D \times N` dimension
        b: 'np.ndarray'
            A matrix with :math:`D \times N` dimension

    Returns
    -------
    dist: 'np.ndarray'
        A numeric value for the different between a and b
    """
    aa = np.sum(a ** 2, axis=0)
    bb = np.sum(b ** 2, axis=0)
    ab = a.T.dot(b)

    aa_repmat = matlib.repmat(aa[:, None], 1, b.shape[1])
    bb_repmat = matlib.repmat(bb[None, :], a.shape[1], 1)

    dist = abs(aa_repmat + bb_repmat - 2 * ab)

    return dist 
開發者ID:aristoteleo,項目名稱:dynamo-release,代碼行數:26,代碼來源:psl.py

示例6: repmat

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def repmat(X, m, n):
    """This function returns an array containing m (n) copies of A in the row (column) dimensions. The size of B is
    size(A)*n when A is a matrix.For example, repmat(np.matrix(1:4), 2, 3) returns a 4-by-6 matrix.
    Arguments
    ---------
        X: 'np.ndarray'
            An array like matrix.
        m: 'int'
            Number of copies on row dimension
        n: 'int'
            Number of copies on column dimension
    Returns
    -------
    xy_rep: 'np.ndarray'
        A matrix of repmat
    """
    xy_rep = matlib.repmat(X, m, n)

    return xy_rep 
開發者ID:aristoteleo,項目名稱:dynamo-release,代碼行數:21,代碼來源:psl.py

示例7: sqdist

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def sqdist(a, b):
    """calculate the square distance between a, b

    Arguments
    ---------
        a: 'np.ndarray'
            A matrix with :math:`D \times N` dimension
        b: 'np.ndarray'
            A matrix with :math:`D \times N` dimension

    Returns
    -------
    dist: 'np.ndarray'
        A numeric value for the different between a and b
    """
    aa = np.sum(a ** 2, axis=0)
    bb = np.sum(b ** 2, axis=0)
    ab = a.T.dot(b)

    aa_repmat = matlib.repmat(aa[:, None], 1, b.shape[1])
    bb_repmat = matlib.repmat(bb[None, :], a.shape[1], 1)

    dist = abs(aa_repmat + bb_repmat - 2 * ab)

    return dist 
開發者ID:aristoteleo,項目名稱:dynamo-release,代碼行數:27,代碼來源:DDRTree.py

示例8: repmat

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def repmat(X, m, n):
    """This function returns an array containing m (n) copies of A in the row (column) dimensions. The size of B is
    size(A)*n when A is a matrix.For example, repmat(np.matrix(1:4), 2, 3) returns a 4-by-6 matrix.

    Arguments
    ---------
        X: 'np.ndarray'
            An array like matrix.
        m: 'int'
            Number of copies on row dimension
        n: 'int'
            Number of copies on column dimension

    Returns
    -------
    xy_rep: 'np.ndarray'
        A matrix of repmat
    """
    xy_rep = matlib.repmat(X, m, n)

    return xy_rep 
開發者ID:aristoteleo,項目名稱:dynamo-release,代碼行數:23,代碼來源:DDRTree.py

示例9: test_freduce

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def test_freduce(self):
        # test with 1D arrays
        fs = np.fft.fftfreq(5)
        self.assertTrue(np.all(ft.freduce(fs) == fs[:-2]))
        fs = np.fft.fftfreq(6)
        self.assertTrue(np.all(ft.freduce(fs) == fs[:-2]))

        # test 2D arrays along both dimensions
        fs = mat.repmat(ft.fscale(500, 0.001), 4, 1)
        self.assertTrue(ft.freduce(fs).shape == (4, 251))
        self.assertTrue(ft.freduce(np.transpose(fs), axis=0).shape == (251, 4)) 
開發者ID:int-brain-lab,項目名稱:ibllib,代碼行數:13,代碼來源:test_dsp.py

示例10: dlnprob

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def dlnprob(self, theta):
        
        if self.batchsize > 0:
            batch = [ i % self.N for i in range(self.iter * self.batchsize, (self.iter + 1) * self.batchsize) ]
            ridx = self.permutation[batch]
            self.iter += 1
        else:
            ridx = np.random.permutation(self.X.shape[0])
            
        Xs = self.X[ridx, :]
        Ys = self.Y[ridx]
        
        w = theta[:, :-1]  # logistic weights
        alpha = np.exp(theta[:, -1])  # the last column is logalpha
        d = w.shape[1]
        
        wt = np.multiply((alpha / 2), np.sum(w ** 2, axis=1))
        
        coff = np.matmul(Xs, w.T)
        y_hat = 1.0 / (1.0 + np.exp(-1 * coff))
        
        dw_data = np.matmul(((nm.repmat(np.vstack(Ys), 1, theta.shape[0]) + 1) / 2.0 - y_hat).T, Xs)  # Y \in {-1,1}
        dw_prior = -np.multiply(nm.repmat(np.vstack(alpha), 1, d) , w)
        dw = dw_data * 1.0 * self.X.shape[0] / Xs.shape[0] + dw_prior  # re-scale
        
        dalpha = d / 2.0 - wt + (self.a0 - 1) - self.b0 * alpha + 1  # the last term is the jacobian term
        
        return np.hstack([dw, np.vstack(dalpha)])  # % first order derivative 
開發者ID:dilinwang820,項目名稱:Stein-Variational-Gradient-Descent,代碼行數:30,代碼來源:bayesian_logistic_regression.py

示例11: evaluation

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def evaluation(self, theta, X_test, y_test):
        theta = theta[:, :-1]
        M, n_test = theta.shape[0], len(y_test)

        prob = np.zeros([n_test, M])
        for t in range(M):
            coff = np.multiply(y_test, np.sum(-1 * np.multiply(nm.repmat(theta[t, :], n_test, 1), X_test), axis=1))
            prob[:, t] = np.divide(np.ones(n_test), (1 + np.exp(coff)))
        
        prob = np.mean(prob, axis=1)
        acc = np.mean(prob > 0.5)
        llh = np.mean(np.log(prob))
        return [acc, llh] 
開發者ID:dilinwang820,項目名稱:Stein-Variational-Gradient-Descent,代碼行數:15,代碼來源:bayesian_logistic_regression.py

示例12: dlnprob

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def dlnprob(self, theta):
        return -1*np.matmul(theta-nm.repmat(self.mu, theta.shape[0], 1), self.A) 
開發者ID:dilinwang820,項目名稱:Stein-Variational-Gradient-Descent,代碼行數:4,代碼來源:multivariate_normal.py

示例13: lineFromTwoPoint

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def lineFromTwoPoint(pt1, pt2):
    '''
    Generate line segment based on two points on panorama
    pt1, pt2: two points on panorama
    line:
        1~3-th dim: normal of the line
        4-th dim: the projection dimension ID
        5~6-th dim: the u of line segment endpoints in projection plane
    '''
    numLine = pt1.shape[0]
    lines = np.zeros((numLine, 6))
    n = np.cross(pt1, pt2)
    n = n / (matlib.repmat(np.sqrt(np.sum(n ** 2, 1, keepdims=1)), 1, 3) + 1e-9)
    lines[:, 0:3] = n

    areaXY = np.abs(np.sum(n * matlib.repmat([0, 0, 1], numLine, 1), 1, keepdims=True))
    areaYZ = np.abs(np.sum(n * matlib.repmat([1, 0, 0], numLine, 1), 1, keepdims=True))
    areaZX = np.abs(np.sum(n * matlib.repmat([0, 1, 0], numLine, 1), 1, keepdims=True))
    planeIDs = np.argmax(np.hstack([areaXY, areaYZ, areaZX]), axis=1) + 1
    lines[:, 3] = planeIDs

    for i in range(numLine):
        uv = xyz2uvN(np.vstack([pt1[i, :], pt2[i, :]]), lines[i, 3])
        umax = uv[:, 0].max() + np.pi
        umin = uv[:, 0].min() + np.pi
        if umax - umin > np.pi:
            lines[i, 4:6] = np.array([umax, umin]) / 2 / np.pi
        else:
            lines[i, 4:6] = np.array([umin, umax]) / 2 / np.pi

    return lines 
開發者ID:zouchuhang,項目名稱:LayoutNetv2,代碼行數:33,代碼來源:pano_gen.py

示例14: _sample_start_state

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def _sample_start_state(self, mean=None, std=None, n_samples=1):
        """ """
        init_std = self.init_std
        if not std is None:
            init_std = std

        init_m = mean
        if init_m is None:
            init_m = self.init_m

        samples = (repmat(init_std, n_samples, 1) * np.random.randn(n_samples, self.n_s)
                   + repmat(init_m, n_samples, 1))
        return samples.T.squeeze() 
開發者ID:befelix,項目名稱:safe-exploration,代碼行數:15,代碼來源:environments.py

示例15: llc

# 需要導入模塊: from numpy import matlib [as 別名]
# 或者: from numpy.matlib import repmat [as 別名]
def llc(X, D, knn=5):
    # the sparse coder introduced in
    # "Locality-constrained Linear Coding for Image Classification"

    n_samples = X.shape[1]
    n_atoms = D.shape[1]
    # has the distance of
    # each sample to each atom
    dist = np.zeros((n_samples, n_atoms))
    # calculate the distances
    for i in range(n_samples):
        for j in range(n_atoms):
            dist[i, j] = norm(X[:, i] - D[:, j])

    # has the indices of the atoms
    # that are nearest neighbour to each sample
    knn_idx = np.zeros((n_samples, knn)).astype(int)
    for i in xrange(n_samples):
        knn_idx[i, :] = np.argsort(dist[i, :])[:knn]
    # the sparse coding matrix
    Z = np.zeros((n_atoms, n_samples))
    II = np.eye(knn)
    beta = 1e-4
    b = np.ones(knn)
    for i in xrange(n_samples):
        idx = knn_idx[i, :]
        z = D.T[idx, :] - repmat(X.T[i, :], knn, 1)
        C = np.dot(z, z.T)
        C = C + II * beta * np.trace(C)
        # solve the linear system C*c=b
        c = solve(C, b)
        # enforce the constraint on the sparse codes
        # such that sum(c)=1
        c = c / float(np.sum(c))
        Z[idx, i] = c

    return Z 
開發者ID:ektormak,項目名稱:Lyssandra,代碼行數:39,代碼來源:sparse_coding.py


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