Save

This notebook shows how to save and load graphs using the Bunch format.

[1]:
import numpy as np
from scipy import sparse
[2]:
from sknetwork.data import Bunch, load, save
[3]:
# random graph
adjacency = sparse.csr_matrix(np.random.random((10, 10)) < 0.2)
[4]:
# names
names = list('abcdefghij')
[5]:
graph = Bunch()
graph.adjacency = adjacency
graph.names = np.array(names)
[6]:
save('mygraph', graph)
[7]:
graph = load('mygraph')
[8]:
graph
[8]:
{'adjacency': <10x10 sparse matrix of type '<class 'numpy.bool_'>'
        with 20 stored elements in Compressed Sparse Row format>,
 'names': array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], dtype='<U1')}