Creates a new graph from an adjacency matrix given as a SciPy sparse array. Parameters ---------- A: scipy.sparse array An adjacency matrix representation of a graph parallel_edges : Boolean If this is True, `create_using` is a multigraph, and `A` is an intege
(
A, parallel_edges=False, create_using=None, edge_attribute="weight"
)
| 775 | |
| 776 | @nx._dispatchable(graphs=None, returns_graph=True) |
| 777 | def from_scipy_sparse_array( |
| 778 | A, parallel_edges=False, create_using=None, edge_attribute="weight" |
| 779 | ): |
| 780 | """Creates a new graph from an adjacency matrix given as a SciPy sparse |
| 781 | array. |
| 782 | |
| 783 | Parameters |
| 784 | ---------- |
| 785 | A: scipy.sparse array |
| 786 | An adjacency matrix representation of a graph |
| 787 | |
| 788 | parallel_edges : Boolean |
| 789 | If this is True, `create_using` is a multigraph, and `A` is an |
| 790 | integer matrix, then entry *(i, j)* in the matrix is interpreted as the |
| 791 | number of parallel edges joining vertices *i* and *j* in the graph. |
| 792 | If it is False, then the entries in the matrix are interpreted as |
| 793 | the weight of a single edge joining the vertices. |
| 794 | |
| 795 | create_using : NetworkX graph constructor, optional (default=nx.Graph) |
| 796 | Graph type to create. If graph instance, then cleared before populated. |
| 797 | |
| 798 | edge_attribute: string |
| 799 | Name of edge attribute to store matrix numeric value. The data will |
| 800 | have the same type as the matrix entry (int, float, (real,imag)). |
| 801 | |
| 802 | Notes |
| 803 | ----- |
| 804 | For directed graphs, explicitly mention create_using=nx.DiGraph, |
| 805 | and entry i,j of A corresponds to an edge from i to j. |
| 806 | |
| 807 | If `create_using` is :class:`networkx.MultiGraph` or |
| 808 | :class:`networkx.MultiDiGraph`, `parallel_edges` is True, and the |
| 809 | entries of `A` are of type :class:`int`, then this function returns a |
| 810 | multigraph (constructed from `create_using`) with parallel edges. |
| 811 | In this case, `edge_attribute` will be ignored. |
| 812 | |
| 813 | If `create_using` indicates an undirected multigraph, then only the edges |
| 814 | indicated by the upper triangle of the matrix `A` will be added to the |
| 815 | graph. |
| 816 | |
| 817 | Examples |
| 818 | -------- |
| 819 | >>> import scipy as sp |
| 820 | >>> A = sp.sparse.eye(2, 2, 1) |
| 821 | >>> G = nx.from_scipy_sparse_array(A) |
| 822 | |
| 823 | If `create_using` indicates a multigraph and the matrix has only integer |
| 824 | entries and `parallel_edges` is False, then the entries will be treated |
| 825 | as weights for edges joining the nodes (without creating parallel edges): |
| 826 | |
| 827 | >>> A = sp.sparse.csr_array([[1, 1], [1, 2]]) |
| 828 | >>> G = nx.from_scipy_sparse_array(A, create_using=nx.MultiGraph) |
| 829 | >>> G[1][1] |
| 830 | AtlasView({0: {'weight': 2}}) |
| 831 | |
| 832 | If `create_using` indicates a multigraph and the matrix has only integer |
| 833 | entries and `parallel_edges` is True, then the entries will be treated |
| 834 | as the number of parallel edges joining those two vertices: |
nothing calls this directly
no test coverage detected
searching dependent graphs…