grapharray.classes.GraphArray¶
- class grapharray.classes.GraphArray(base_graph: grapharray.classes.BaseGraph, init_val=0, is_array_2d: bool = False)[source]¶
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
- __init__(base_graph: grapharray.classes.BaseGraph, init_val=0, is_array_2d: bool = False)[source]¶
Set the initial value of array.
Methods
__init__
(base_graph[, init_val, is_array_2d])Set the initial value of array.
as_dict
()Return values of variables as a dictionary keyed by node/edge.
as_nx_graph
([assign_to])Return a nx.DiGraph with the array elements as node/edge attributes.
get_copy
()Make a copy of self.
Attributes
T
Transpose the array
Core array
base_graph
BaseGraph object on that this array itself is defined
edge_to_index
Correspondence between edges and array indices
edges
Tuple of all edges
Correspondence between the array indices and the nodes/edges.
Whether the array is 2-dimensional or not
is_transposed
Whether the array is transposed or not.
node_to_index
Correspondence between nodes and array indices
nodes
Tuple of all nodes
number_of_edges
The number of edges in the base graph
number_of_nodes
The number of nodes in the base graph