xgi.readwrite.edgelist#
Read from and write to edgelists.
Functions
- generate_edgelist(H, delimiter=' ')[source]#
A helper function to generate a hyperedge list from a Hypergraph object.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
- Yields:
iterator of strings – Each entry is a line for the file to write.
- parse_edgelist(lines, comments='#', delimiter=None, create_using=None, nodetype=None)[source]#
A helper function to read a iterable of strings containing a hyperedge list and convert it to a Hypergraph object.
- Parameters:
lines (iterable of strings) – Lines where each line is an edge
comments (string, default: "#") – The token that denotes comments to ignore
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
create_using (Hypergraph constructor, optional) – The hypergraph object to add the data to, by default None
nodetype (type) – type that the node labels will be cast to
- Returns:
The loaded hypergraph
- Return type:
Hypergraph object
- read_edgelist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
Read a file containing a hyperedge list and convert it to a Hypergraph object.
- Parameters:
path (string) – The path of the file to read from
comments (string, default: "#") – The token that denotes comments in the file
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
create_using (Hypergraph constructor, optional) – The hypergraph object to add the data to, by default None
nodetype (type) – type that the node labels will be cast to
encoding (string, default: "utf-8") – Encoding of the file
- Returns:
The loaded hypergraph
- Return type:
Hypergraph object
See also
read_weighted_edgelist
Examples
>>> import xgi >>> # H = xgi.read_edgelist("test.csv", delimiter=",")
- write_edgelist(H, path, delimiter=' ', encoding='utf-8')[source]#
Create a file containing a hyperedge list from a Hypergraph object.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
path (string) – The path of the file to write to
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
encoding (string, default: "utf-8") – Encoding of the file
Examples
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.01, 0.001]) >>> # xgi.write_edgelist(H, "test.csv", delimiter=",")