保存

此笔记本展示了如何使用 Bunch 格式保存和加载图。

[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 23 stored elements in Compressed Sparse Row format>,
 'names': array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], dtype='<U1')}