示例#1
0
    def tocsc(self):
        indptr = np.empty(self.shape[1] + 1, dtype=np.intc)
        indices = np.empty(self.nnz, dtype=np.intc)
        data = np.empty(self.nnz, dtype=upcast(self.dtype))

        csr_tocsc(self.shape[0], self.shape[1], self.indptr, self.indices, self.data, indptr, indices, data)

        from csc import csc_matrix

        A = csc_matrix((data, indices, indptr), shape=self.shape)
        A.has_sorted_indices = True
        return A
示例#2
0
 def getcol(self, j):
     """Returns a copy of column j of the matrix, as an (m x 1) sparse
     matrix (column vector).
     """
     # Spmatrix subclasses should override this method for efficiency.
     # Post-multiply by a (n x 1) column vector 'a' containing all zeros
     # except for a_j = 1
     from csc import csc_matrix
     n = self.shape[1]
     a = csc_matrix((n, 1), dtype=self.dtype)
     a[j, 0] = 1
     return self * a
示例#3
0
    def tocsc(self):
        indptr = np.empty(self.shape[1] + 1, dtype=np.intc)
        indices = np.empty(self.nnz, dtype=np.intc)
        data = np.empty(self.nnz, dtype=upcast(self.dtype))

        csr_tocsc(self.shape[0], self.shape[1], \
                  self.indptr, self.indices, self.data, \
                  indptr, indices, data)

        from csc import csc_matrix
        A = csc_matrix((data, indices, indptr), shape=self.shape)
        A.has_sorted_indices = True
        return A
示例#4
0
    def tocsc(self):
        """Return a copy of this matrix in Compressed Sparse Column format

        Duplicate entries will be summed together.

        Example
        -------
        >>> from numpy import array
        >>> from scipy.sparse import coo_matrix
        >>> row  = array([0,0,1,3,1,0,0])
        >>> col  = array([0,2,1,3,1,0,0])
        >>> data = array([1,1,1,1,1,1,1])
        >>> A = coo_matrix( (data,(row,col)), shape=(4,4)).tocsc()
        >>> A.todense()
        matrix([[3, 0, 1, 0],
                [0, 2, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 1]])

        """
        from csc import csc_matrix
        if self.nnz == 0:
            return csc_matrix(self.shape, dtype=self.dtype)
        else:
            M,N = self.shape
            indptr  = np.empty(N + 1,    dtype=np.intc)
            indices = np.empty(self.nnz, dtype=np.intc)
            data    = np.empty(self.nnz, dtype=upcast(self.dtype))

            coo_tocsr(N, M, self.nnz, \
                      self.col, self.row, self.data, \
                      indptr, indices, data)

            A = csc_matrix((data, indices, indptr), shape=self.shape)
            A.sum_duplicates()

            return A
示例#5
0
文件: coo.py 项目: afarahi/QFT
    def tocsc(self):
        """Return a copy of this matrix in Compressed Sparse Column format

        Duplicate entries will be summed together.

        Examples
        --------
        >>> from numpy import array
        >>> from scipy.sparse import coo_matrix
        >>> row  = array([0,0,1,3,1,0,0])
        >>> col  = array([0,2,1,3,1,0,0])
        >>> data = array([1,1,1,1,1,1,1])
        >>> A = coo_matrix( (data,(row,col)), shape=(4,4)).tocsc()
        >>> A.todense()
        matrix([[3, 0, 1, 0],
                [0, 2, 0, 0],
                [0, 0, 0, 0],
                [0, 0, 0, 1]])

        """
        from csc import csc_matrix
        if self.nnz == 0:
            return csc_matrix(self.shape, dtype=self.dtype)
        else:
            M, N = self.shape
            indptr = np.empty(N + 1, dtype=np.intc)
            indices = np.empty(self.nnz, dtype=np.intc)
            data = np.empty(self.nnz, dtype=upcast(self.dtype))

            coo_tocsr(N, M, self.nnz, \
                      self.col, self.row, self.data, \
                      indptr, indices, data)

            A = csc_matrix((data, indices, indptr), shape=self.shape)
            A.sum_duplicates()

            return A
示例#6
0
 def getcol(self, j):
     """Returns a copy of column j of the matrix, as an (m x 1) sparse
     matrix (column vector).
     """
     # Spmatrix subclasses should override this method for efficiency.
     # Post-multiply by a (n x 1) column vector 'a' containing all zeros
     # except for a_j = 1
     from csc import csc_matrix
     n = self.shape[1]
     if j < 0:
         j += n
     if j < 0 or j >= n:
         raise IndexError("index out of bounds")
     col_selector = csc_matrix(([1], [[j], [0]]), shape=(n,1), dtype=self.dtype)
     return self * col_selector
示例#7
0
文件: base.py 项目: 87/scipy
 def getcol(self, j):
     """Returns a copy of column j of the matrix, as an (m x 1) sparse
     matrix (column vector).
     """
     # Spmatrix subclasses should override this method for efficiency.
     # Post-multiply by a (n x 1) column vector 'a' containing all zeros
     # except for a_j = 1
     from csc import csc_matrix
     n = self.shape[1]
     if j < 0:
         j += n
     if j < 0 or j >= n:
         raise IndexError("index out of bounds")
     col_selector = csc_matrix(([1], [[j], [0]]), shape=(n,1), dtype=self.dtype)
     return self * col_selector
示例#8
0
 def transpose(self, copy=False):
     from csc import csc_matrix
     M,N = self.shape
     return csc_matrix((self.data,self.indices,self.indptr), shape=(N,M), copy=copy)
示例#9
0
 def transpose(self, copy=False):
     from csc import csc_matrix
     M, N = self.shape
     return csc_matrix((self.data, self.indices, self.indptr),
                       shape=(N, M),
                       copy=copy)