{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Save" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook shows how to save and load graphs using the ``Bunch`` format." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import sparse" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2019-11-25T09:09:39.576284Z", "start_time": "2019-11-25T09:09:39.018204Z" }, "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "from sknetwork.data import Bunch, load, save" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# random graph\n", "adjacency = sparse.csr_matrix(np.random.random((10, 10)) < 0.2)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# names\n", "names = list('abcdefghij')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "graph = Bunch()\n", "graph.adjacency = adjacency\n", "graph.names = np.array(names)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "save('mygraph', graph)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "graph = load('mygraph')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'adjacency': <10x10 sparse matrix of type ''\n", " \twith 25 stored elements in Compressed Sparse Row format>,\n", " 'names': array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], dtype='