ó ŸÃÒYc@spdZddlZdjdddgƒZddd gZddedd „Zdd d „Z e Z d „Z dS(s2 Adjacency matrix and incidence matrix of graphs. iÿÿÿÿNs sAric Hagberg (hagberg@lanl.gov)sPieter Swart (swart@lanl.gov)sDan Schult(dschult@colgate.edu)tincidence_matrixt adj_matrixtadjacency_matrixcCsðddl}|dkr't|ƒ}n|dkro|jƒrZt|jdtƒƒ}qot|jƒƒ}n|jjt|ƒt|ƒfƒ}t d„t |ƒDƒƒ}x1t |ƒD]#\}} | d \} } | | krêq¼ny|| } || } Wn*t k r.t j d| | fƒ‚nX|dkrDd}nQ|jƒr{| d}|| | |j|dƒ}n|| | j|dƒ}|r¿| || |f<||| |fPsis-node %s or %s in edgelist but not in nodelistitcsc(t scipy.sparsetNonetlistt is_multigraphtedgestTruetsparset lil_matrixtlentdictt enumeratetKeyErrortnxt NetworkXErrortgettasformat(tGtnodelisttedgelisttorientedtweighttscipytAt node_indexteitetutvtuitvitwttekey((sq/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/linalg/graphmatrix.pyRs>3    $        !RcCstj|d|d|ƒS(s<Return adjacency matrix of G. Parameters ---------- G : graph A NetworkX graph nodelist : list, optional The rows and columns are ordered according to the nodes in nodelist. If nodelist is None, then the ordering is produced by G.nodes(). weight : string or None, optional (default='weight') The edge data key used to provide each value in the matrix. If None, then each edge has weight 1. Returns ------- A : SciPy sparse matrix Adjacency matrix representation of G. Notes ----- For directed graphs, entry i,j corresponds to an edge from i to j. If you want a pure Python adjacency matrix representation try networkx.convert.to_dict_of_dicts which will return a dictionary-of-dictionaries format that can be addressed as a sparse matrix. For MultiGraph/MultiDiGraph with parallel edges the weights are summed. See to_numpy_matrix for other options. The convention used for self-loop edges in graphs is to assign the diagonal matrix entry value to the edge weight attribute (or the number 1 if the edge has no weight attribute). If the alternate convention of doubling the edge weight is desired the resulting Scipy sparse matrix can be modified as follows: >>> import scipy as sp >>> G = nx.Graph([(1,1)]) >>> A = nx.adjacency_matrix(G) >>> print(A.todense()) [[1]] >>> A.setdiag(A.diagonal()*2) >>> print(A.todense()) [[2]] See Also -------- to_numpy_matrix to_scipy_sparse_matrix to_dict_of_dicts RR(Rtto_scipy_sparse_matrix(RRR((sq/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/linalg/graphmatrix.pyRls6cCs:ddlm}yddl}Wn|dƒ‚nXdS(Niÿÿÿÿ(tSkipTestsSciPy not available(tnoseR)R(tmoduleR)R((sq/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/linalg/graphmatrix.pyt setup_moduleªs ( t__doc__tnetworkxRtjoint __author__t__all__R tFalseRRRR,(((sq/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/linalg/graphmatrix.pyts    W9