numpy.matlib.repmat - python examples

Here are the examples of the python api numpy.matlib.repmat taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

39 Examples 7

3 View Complete Implementation : test_matlib.py
Copyright MIT License
Author : abhisuri97
def test_repmat():
    a1 = np.arange(4)
    x = numpy.matlib.repmat(a1, 2, 2)
    y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
                  [0, 1, 2, 3, 0, 1, 2, 3]])
    astert_array_equal(x, y)

3 View Complete Implementation : psl.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : aristoteleo
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

3 View Complete Implementation : environments.py
Copyright MIT License
Author : befelix
    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()

3 View Complete Implementation : utils.py
Copyright MIT License
Author : befelix
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()

3 View Complete Implementation : bayesian_logistic_regression.py
Copyright MIT License
Author : dilinwang820
    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]

3 View Complete Implementation : util.py
Copyright GNU General Public License v3.0
Author : masabdi
    def setNormSkel(self, norm_skel):
        if len(norm_skel)%3 != 0:
            raise ValueError('invalid length of the skeleton mat')
        jntNum = len(norm_skel)/3
        self.norm_skel = norm_skel.copy().astype(np.float32)
        self.crop_skel = norm_skel.copy()*self.skel_norm_ratio
        self.com3D = np.zeros([3])
        self.com3D[2] = 200
        self.skel = (self.crop_skel + repmat(self.com3D, 1, jntNum))[0]
        self.skel = self.skel.astype(np.float32)

3 View Complete Implementation : util.py
Copyright GNU General Public License v3.0
Author : masabdi
    def setCropSkel(self, crop_skel):
        if len(crop_skel)%3 != 0:
            raise ValueError('invalid length of the skeleton mat')
        jntNum = len(crop_skel)/3
        self.crop_skel = crop_skel.astype(np.float32)
        self.skel = (self.crop_skel + repmat(self.com3D, 1, jntNum))[0]
        self.skel = self.skel.astype(np.float32)
        self.normSkel()

3 View Complete Implementation : util.py
Copyright GNU General Public License v3.0
Author : masabdi
    def setSkel(self, skel):
        if len(skel)%3 != 0:
            raise ValueError('invalid length of the skeleton mat')
        jntNum = len(skel)/3
        self.skel = skel.astype(np.float32)
        #crop_skel is the training label for neurual network, normalize wrt com3D
        self.crop_skel = (self.skel - repmat(self.com3D, 1, jntNum))[0]
        self.crop_skel = self.crop_skel.astype(np.float32)
        self.normSkel()

3 View Complete Implementation : util.py
Copyright GNU General Public License v3.0
Author : masabdi
    def crop2D(self):
        self.crop_skel = self.norm_skel * np.float32(50.0)
        skel = self.crop_skel.copy()
        jntNum = len(skel)/3
        skel = skel.reshape(-1, 3)
        skel += repmat(self.com3D, jntNum, 1)
        for i, jnt in enumerate(skel):
            jnt = Camera.to2D(jnt)
            pt = np.array([jnt[0],jnt[1], 1.0], np.float32).reshape(3,1)
            pt = self.trans*pt
            skel[i,0], skel[i,1] = pt[0], pt[1]
        return skel

3 View Complete Implementation : pattern_clustering.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : mehrdadbakhtiari
def get_elbow_point_index(wcss):
    curve = wcss
    number_of_points = len(curve)
    all_coordinates = np.vstack((range(number_of_points), curve)).T
    np.array([range(number_of_points), curve])
    first_point = all_coordinates[0]
    line_vector = all_coordinates[-1] - all_coordinates[0]
    line_vector_norm = line_vector / np.sqrt(np.sum(line_vector**2))
    vec_from_first = all_coordinates - first_point
    scalar_product = np.sum(vec_from_first * matlib.repmat(line_vector_norm, number_of_points, 1), axis=1)
    vec_from_first_parallel = np.outer(scalar_product, line_vector_norm)
    vectors_to_line = vec_from_first - vec_from_first_parallel
    dists_to_line = np.sqrt(np.sum(vectors_to_line ** 2, axis=1))
    index_of_best_point = np.argmax(dists_to_line)
    return index_of_best_point