Returns the graph adjacency matrix as a NumPy array. Parameters ---------- G : graph The NetworkX graph used to construct the NumPy array. nodelist : list, optional The rows and columns are ordered according to the nodes in `nodelist`. If `nodelist` is ``Non
(
G,
nodelist=None,
dtype=None,
order=None,
multigraph_weight=sum,
weight="weight",
nonedge=0.0,
)
| 880 | |
| 881 | @nx._dispatchable(edge_attrs="weight") # edge attrs may also be obtained from `dtype` |
| 882 | def to_numpy_array( |
| 883 | G, |
| 884 | nodelist=None, |
| 885 | dtype=None, |
| 886 | order=None, |
| 887 | multigraph_weight=sum, |
| 888 | weight="weight", |
| 889 | nonedge=0.0, |
| 890 | ): |
| 891 | """Returns the graph adjacency matrix as a NumPy array. |
| 892 | |
| 893 | Parameters |
| 894 | ---------- |
| 895 | G : graph |
| 896 | The NetworkX graph used to construct the NumPy array. |
| 897 | |
| 898 | nodelist : list, optional |
| 899 | The rows and columns are ordered according to the nodes in `nodelist`. |
| 900 | If `nodelist` is ``None``, then the ordering is produced by ``G.nodes()``. |
| 901 | |
| 902 | dtype : NumPy data type, optional |
| 903 | A NumPy data type used to initialize the array. If None, then the NumPy |
| 904 | default is used. The dtype can be structured if `weight=None`, in which |
| 905 | case the dtype field names are used to look up edge attributes. The |
| 906 | result is a structured array where each named field in the dtype |
| 907 | corresponds to the adjacency for that edge attribute. See examples for |
| 908 | details. |
| 909 | |
| 910 | order : {'C', 'F'}, optional |
| 911 | Whether to store multidimensional data in C- or Fortran-contiguous |
| 912 | (row- or column-wise) order in memory. If None, then the NumPy default |
| 913 | is used. |
| 914 | |
| 915 | multigraph_weight : callable, optional |
| 916 | An function that determines how weights in multigraphs are handled. |
| 917 | The function should accept a sequence of weights and return a single |
| 918 | value. The default is to sum the weights of the multiple edges. |
| 919 | |
| 920 | weight : string or None optional (default = 'weight') |
| 921 | The edge attribute that holds the numerical value used for |
| 922 | the edge weight. If an edge does not have that attribute, then the |
| 923 | value 1 is used instead. `weight` must be ``None`` if a structured |
| 924 | dtype is used. |
| 925 | |
| 926 | nonedge : array_like (default = 0.0) |
| 927 | The value used to represent non-edges in the adjacency matrix. |
| 928 | The array values corresponding to nonedges are typically set to zero. |
| 929 | However, this could be undesirable if there are array values |
| 930 | corresponding to actual edges that also have the value zero. If so, |
| 931 | one might prefer nonedges to have some other value, such as ``nan``. |
| 932 | |
| 933 | Returns |
| 934 | ------- |
| 935 | A : NumPy ndarray |
| 936 | Graph adjacency matrix |
| 937 | |
| 938 | Raises |
| 939 | ------ |
no test coverage detected
searching dependent graphs…