コード例 #1
0
ファイル: test_graph.py プロジェクト: Garyfallidis/nipy
 def test_graph_create_from_coo_matrix(self):
     """
     Test the creation of a graph from a sparse coo_matrix 
     """
     import scipy.sparse as spp
     a = np.random.randn(5, 5)>.8
     s = spp.coo_matrix(a)
     wg = fg.wgraph_from_coo_matrix(s)
     b = wg.adjacency()
     self.assert_((a==b).all())
コード例 #2
0
ファイル: discrete_domain.py プロジェクト: miketrumpis/nipy
def reduce_coo_matrix(mat, mask):
    """
    reduce a supposedly coo_matrix to the vertices in the mask

    Parameters
    ----------
    mat: sparse coo_matrix,
         input matrix
    mask: boolean array of shape mat.shape[0],
          desired elements 
    """
    G = fg.wgraph_from_coo_matrix(mat)
    K = G.subgraph(mask)
    return K.to_coo_matrix()