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


Python sparse.isspmatrix_coo方法代碼示例

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


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

示例1: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    """Convert sparse matrix to tuple representation."""
    def to_tuple(mx):
        if not sp.isspmatrix_coo(mx):
            mx = mx.tocoo()
        coords = np.vstack((mx.row, mx.col)).transpose()
        values = mx.data
        shape = mx.shape
        return coords, values, shape

    if isinstance(sparse_mx, list):
        for i in range(len(sparse_mx)):
            sparse_mx[i] = to_tuple(sparse_mx[i])
    else:
        sparse_mx = to_tuple(sparse_mx)

    return sparse_mx 
開發者ID:thunlp,項目名稱:OpenNE,代碼行數:19,代碼來源:utils.py

示例2: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    """Convert sparse matrix to tuple representation."""

    def to_tuple(mx):
        if not sp.isspmatrix_coo(mx):
            mx = mx.tocoo()
        coords = np.vstack((mx.row, mx.col)).transpose()
        values = mx.data
        shape = mx.shape
        return coords, values, shape

    if isinstance(sparse_mx, list):
        for i in range(len(sparse_mx)):
            sparse_mx[i] = to_tuple(sparse_mx[i])
    else:
        sparse_mx = to_tuple(sparse_mx)

    return sparse_mx 
開發者ID:JudyYe,項目名稱:zero-shot-gcn,代碼行數:20,代碼來源:utils.py

示例3: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    """Convert sparse matrix to tuple representation."""
    def to_tuple(mx):
        if not sp.isspmatrix_coo(mx):
            mx = mx.tocoo()
        coords = np.vstack((mx.row, mx.col)).transpose()
        values = mx.data
        shape = mx.shape
        # All of these will need to be sorted:
        sort_indices = np.lexsort(np.rot90(coords))
        return coords[sort_indices], values[sort_indices], shape

    if isinstance(sparse_mx, list):
        for i in range(len(sparse_mx)):
            sparse_mx[i] = to_tuple(sparse_mx[i])
    else:
        sparse_mx = to_tuple(sparse_mx)

    return sparse_mx 
開發者ID:microsoft,項目名稱:tf-gnn-samples,代碼行數:21,代碼來源:citation_network_utils.py

示例4: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx, insert_batch=False):
    """Convert sparse matrix to tuple representation."""
    """Set insert_batch=True if you want to insert a batch dimension."""
    def to_tuple(mx):
        if not sp.isspmatrix_coo(mx):
            mx = mx.tocoo()
        if insert_batch:
            coords = np.vstack((np.zeros(mx.row.shape[0]), mx.row, mx.col)).transpose()
            values = mx.data
            shape = (1,) + mx.shape
        else:
            coords = np.vstack((mx.row, mx.col)).transpose()
            values = mx.data
            shape = mx.shape
        return coords, values, shape

    if isinstance(sparse_mx, list):
        for i in range(len(sparse_mx)):
            sparse_mx[i] = to_tuple(sparse_mx[i])
    else:
        sparse_mx = to_tuple(sparse_mx)

    return sparse_mx 
開發者ID:PetarV-,項目名稱:DGI,代碼行數:25,代碼來源:process.py

示例5: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
        """Convert sparse matrix to tuple representation."""
        def to_tuple(mx):
                if not sp.isspmatrix_coo(mx):
                        mx = mx.tocoo()
                coords = np.vstack((mx.row, mx.col)).transpose()
                values = mx.data
                shape = mx.shape
                return coords, values, shape

        if isinstance(sparse_mx, list):
                for i in range(len(sparse_mx)):
                        sparse_mx[i] = to_tuple(sparse_mx[i])
        else:
                sparse_mx = to_tuple(sparse_mx)

        return sparse_mx 
開發者ID:malllabiisc,項目名稱:ConfGCN,代碼行數:19,代碼來源:helper.py

示例6: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    def to_tuple(mx):
        if not sp.isspmatrix_coo(mx):
            mx = mx.tocoo()
        coords = np.vstack((mx.row, mx.col)).transpose()
        values = mx.data
        shape = mx.shape
        return coords, values, shape

    if isinstance(sparse_mx, list):
        for i in range(len(sparse_mx)):
            sparse_mx[i] = to_tuple(sparse_mx[i])
    else:
        sparse_mx = to_tuple(sparse_mx)

    return sparse_mx 
開發者ID:daiquocnguyen,項目名稱:Graph-Transformer,代碼行數:18,代碼來源:util.py

示例7: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    """ change of format for sparse matrix. This format is used
    for the feed_dict where sparse matrices need to be linked to placeholders
    representing sparse matrices. """

    if not sp.isspmatrix_coo(sparse_mx):
        sparse_mx = sparse_mx.tocoo()
    coords = np.vstack((sparse_mx.row, sparse_mx.col)).transpose()
    values = sparse_mx.data
    shape = sparse_mx.shape
    return coords, values, shape 
開發者ID:muhanzhang,項目名稱:IGMC,代碼行數:13,代碼來源:preprocessing.py

示例8: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_matrix):
    if not sp.isspmatrix_coo(sparse_matrix):
        sparse_matrix = sparse_matrix.tocoo()
    indices = np.vstack((sparse_matrix.row, sparse_matrix.col)).transpose()
    values = sparse_matrix.data
    shape = sparse_matrix.shape
    return indices, values, shape 
開發者ID:hwwang55,項目名稱:PathCon,代碼行數:9,代碼來源:utils.py

示例9: sparse_to_tuple

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def sparse_to_tuple(sparse_mx):
    if not sp.isspmatrix_coo(sparse_mx):
        sparse_mx = sparse_mx.tocoo()
    coords = np.vstack((sparse_mx.row, sparse_mx.col)).transpose()
    values = sparse_mx.data
    shape = sparse_mx.shape
    return coords, values, shape 
開發者ID:DaehanKim,項目名稱:vgae_pytorch,代碼行數:9,代碼來源:preprocessing.py

示例10: test_sparse_dtm

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def test_sparse_dtm(docs, pass_vocab):
    if pass_vocab:
        vocab = vocabulary(docs, sort=True)
        dtm = sparse_dtm(docs, vocab)
    else:
        dtm, vocab = sparse_dtm(docs)

    assert isspmatrix_coo(dtm)
    assert dtm.shape == (len(docs), len(vocab))
    assert vocab == vocabulary(docs, sort=True) 
開發者ID:WZBSocialScienceCenter,項目名稱:tmtoolkit,代碼行數:12,代碼來源:test_preprocess_func.py

示例11: test_add_dummy_feature_coo

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def test_add_dummy_feature_coo():
    X = sparse.coo_matrix([[1, 0], [0, 1], [0, 1]])
    X = add_dummy_feature(X)
    assert sparse.isspmatrix_coo(X), X
    assert_array_equal(X.toarray(), [[1, 1, 0], [1, 0, 1], [1, 0, 1]]) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:7,代碼來源:test_data.py

示例12: test_coo

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def test_coo(self):
        x = sparse.coo_matrix(
            (cupy.array([0], 'f'),
             (cupy.array([0], 'i'), cupy.array([0], 'i'))),
            shape=(1, 1), dtype='f')
        self.assertTrue(sparse.isspmatrix_coo(x)) 
開發者ID:cupy,項目名稱:cupy,代碼行數:8,代碼來源:test_coo.py

示例13: test_csr

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def test_csr(self):
        x = sparse.csr_matrix(
            (cupy.array([], 'f'),
             cupy.array([], 'i'),
             cupy.array([0], 'i')),
            shape=(0, 0), dtype='f')
        self.assertFalse(sparse.isspmatrix_coo(x)) 
開發者ID:cupy,項目名稱:cupy,代碼行數:9,代碼來源:test_coo.py

示例14: save_sparse

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def save_sparse(sparse_matrix, output_filename):
    assert sparse.issparse(sparse_matrix)
    if sparse.isspmatrix_coo(sparse_matrix):
        coo = sparse_matrix
    else:
        coo = sparse_matrix.tocoo()
    row = coo.row
    col = coo.col
    data = coo.data
    shape = coo.shape
    np.savez(output_filename, row=row, col=col, data=data, shape=shape) 
開發者ID:dallascard,項目名稱:scholar,代碼行數:13,代碼來源:file_handling.py

示例15: preprocess_adj_bias

# 需要導入模塊: from scipy import sparse [as 別名]
# 或者: from scipy.sparse import isspmatrix_coo [as 別名]
def preprocess_adj_bias(adj):
    num_nodes = adj.shape[0]
    adj = adj + sp.eye(num_nodes)  # self-loop
    adj[adj > 0.0] = 1.0
    if not sp.isspmatrix_coo(adj):
        adj = adj.tocoo()
    adj = adj.astype(np.float32)
    indices = np.vstack((adj.col, adj.row)).transpose()
    return indices, adj.data, adj.shape 
開發者ID:didi,項目名稱:hetsann,代碼行數:11,代碼來源:process.py


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