本文整理匯總了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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]])
示例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))
示例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))
示例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)
示例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