Returns the graph adjacency matrix as a NumPy array. Parameters ---------- G : graph The EasyGraph 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 None
(
G,
nodelist=None,
dtype=None,
order=None,
multigraph_weight=sum,
weight="weight",
nonedge=0.0,
)
| 421 | |
| 422 | |
| 423 | def to_numpy_array( |
| 424 | G, |
| 425 | nodelist=None, |
| 426 | dtype=None, |
| 427 | order=None, |
| 428 | multigraph_weight=sum, |
| 429 | weight="weight", |
| 430 | nonedge=0.0, |
| 431 | ): |
| 432 | """Returns the graph adjacency matrix as a NumPy array. |
| 433 | |
| 434 | Parameters |
| 435 | ---------- |
| 436 | G : graph |
| 437 | The EasyGraph graph used to construct the NumPy array. |
| 438 | |
| 439 | nodelist : list, optional |
| 440 | The rows and columns are ordered according to the nodes in `nodelist`. |
| 441 | If `nodelist` is None, then the ordering is produced by G.nodes(). |
| 442 | |
| 443 | dtype : NumPy data type, optional |
| 444 | A valid single NumPy data type used to initialize the array. |
| 445 | This must be a simple type such as int or numpy.float64 and |
| 446 | not a compound data type (see to_numpy_recarray) |
| 447 | If None, then the NumPy default is used. |
| 448 | |
| 449 | order : {'C', 'F'}, optional |
| 450 | Whether to store multidimensional data in C- or Fortran-contiguous |
| 451 | (row- or column-wise) order in memory. If None, then the NumPy default |
| 452 | is used. |
| 453 | |
| 454 | multigraph_weight : {sum, min, max}, optional |
| 455 | An operator that determines how weights in multigraphs are handled. |
| 456 | The default is to sum the weights of the multiple edges. |
| 457 | |
| 458 | weight : string or None optional (default = 'weight') |
| 459 | The edge attribute that holds the numerical value used for |
| 460 | the edge weight. If an edge does not have that attribute, then the |
| 461 | value 1 is used instead. |
| 462 | |
| 463 | nonedge : float (default = 0.0) |
| 464 | The array values corresponding to nonedges are typically set to zero. |
| 465 | However, this could be undesirable if there are array values |
| 466 | corresponding to actual edges that also have the value zero. If so, |
| 467 | one might prefer nonedges to have some other value, such as nan. |
| 468 | |
| 469 | Returns |
| 470 | ------- |
| 471 | A : NumPy ndarray |
| 472 | Graph adjacency matrix |
| 473 | |
| 474 | See Also |
| 475 | -------- |
| 476 | from_numpy_array |
| 477 | |
| 478 | Notes |
| 479 | ----- |
| 480 | For directed graphs, entry i,j corresponds to an edge from i to j. |
nothing calls this directly
no test coverage detected