grapharray.classes module¶
Graph Variables
|
Directed graph object on which arrays are defined. |
|
Base object for creating vectors and matrices on networks. |
|
Extracted codes shared between NodeArray and EdgeArray. |
|
Object of variables defined on the nodes. |
|
Object of variables defined on the edges. |
|
N x N matrix |
|
Node-edge incidence matrix |
- class grapharray.classes.AdjacencyMatrix(weight: grapharray.classes.EdgeArray, sparse_format: str = 'csr')[source]¶
Bases:
grapharray.classes.BaseGraphArray
N x N matrix
- class grapharray.classes.BaseGraph(incoming_graph_data=None, **attr)[source]¶
Bases:
networkx.classes.digraph.DiGraph
Directed graph object on which arrays are defined.
This object works (1) as a key to check if variables are defined on the same network and (2) as a holder of the orders of nodes and edges. Note that this object itself does not contain any variables.
- property edge_to_index¶
Correspondence between edges and array indices
- freeze()[source]¶
Freeze the graph and map between nodes / edges and array indices
This method must be called before the instance is passed to array initialization methods.
- property node_to_index¶
Correspondence between nodes and array indices
- class grapharray.classes.BaseGraphArray(base_graph: grapharray.classes.BaseGraph)[source]¶
Bases:
object
Base object for creating vectors and matrices on networks.
This set up attributes used in both node variables and edge variables. All attributes are aliases of that of BaseGraph and thus are read-only.
- property T¶
Transpose the array
- property array¶
Core array
- property base_graph¶
BaseGraph object on that this array itself is defined
- property edge_to_index¶
Correspondence between edges and array indices
- property edges¶
Tuple of all edges
- property is_transposed¶
Whether the array is transposed or not.
- property node_to_index¶
Correspondence between nodes and array indices
- property nodes¶
Tuple of all nodes
- property number_of_edges¶
The number of edges in the base graph
- property number_of_nodes¶
The number of nodes in the base graph
- class grapharray.classes.EdgeArray(base_graph: grapharray.classes.BaseGraph, init_val=0, is_array_2d: bool = False)[source]¶
Bases:
grapharray.classes.GraphArray
Object of variables defined on the edges.
- property index¶
Correspondence between the array indices and the edges.
- class grapharray.classes.GraphArray(base_graph: grapharray.classes.BaseGraph, init_val=0, is_array_2d: bool = False)[source]¶
Bases:
grapharray.classes.BaseGraphArray
Extracted codes shared between NodeArray and EdgeArray.
- Parameters
base_graph (BaseGraph) – The graph on that the variable is defined.
init_val – The initial value of the array.
is_array_2d (bool) – Whether the array is 2-dimensional column vectors. Default is False, which means that the array is 1-dimensional.
Notes
init_val must be either scalar, NodeVar object or {node: value} dictionary. if a scalar is given, all elements of array are set to the init_val. if a NodeVar object is given, a copy of its array is used as initial values. if a dictionary is given, the value on each node/edge is used as initial value of corresponding node/node. if np.ndarray is given, it is directly used as the initial values. This is used to make arithmetic operations faster by avoiding unnecessary array creation.
- array¶
An array that has values linked to nodes/edges.
- Type
np.ndarray
- as_nx_graph(assign_to=None)[source]¶
Return a nx.DiGraph with the array elements as node/edge attributes.
- get_copy()[source]¶
Make a copy of self.
The array of the copy created by this method is a copy of the original, while the base_graph of the copy is the same instance of the original. This is different from the copy created by copy.deepcopy() in that both the array and the base_graph is a copy of the original.
- property index¶
Correspondence between the array indices and the nodes/edges.
This is only a dummy implementation here and overridden in subclasses.
- property is_2d¶
Whether the array is 2-dimensional or not
- class grapharray.classes.IncidenceMatrix(base_graph: grapharray.classes.BaseGraph)[source]¶
Bases:
grapharray.classes.BaseGraphArray
Node-edge incidence matrix
- class grapharray.classes.NodeArray(base_graph: grapharray.classes.BaseGraph, init_val=0, is_array_2d: bool = False)[source]¶
Bases:
grapharray.classes.GraphArray
Object of variables defined on the nodes.
- property index¶
Correspondence between the array indices and the nodes.