Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
rustworkx.PyDiGraph.from_adjacency_matrix#
- static PyDiGraph.from_adjacency_matrix(matrix, /, null_value=0.0)#
Create a new
PyDiGraph
object from an adjacency matrix with matrix elements of typefloat
This method can be used to construct a new
PyDiGraph
object from an input adjacency matrix. The node weights will be the index from the matrix. The edge weights will be a float value of the value from the matrix.This differs from the
from_complex_adjacency_matrix()
in that the type of the elements of input matrix must be afloat
(specifically anumpy.float64
) and the output graph edge weights will befloat
too. While infrom_complex_adjacency_matrix()
the matrix elements are of typecomplex
(specificallynumpy.complex128
) and the edge weights in the output graph will becomplex
too.- Parameters:
matrix (ndarray) – The input numpy array adjacency matrix to create a new
PyDiGraph
object from. It must be a 2 dimensional array and be afloat
/np.float64
data type.null_value (float) – An optional float that will treated as a null value. If any element in the input matrix is this value it will be treated as not an edge. By default this is
0.0
- Returns:
A new graph object generated from the adjacency matrix
- Return type: