xgi.readwrite.incidence

Read from and write to incidece matrices.

Functions

xgi.readwrite.incidence.read_incidence_matrix(path, comments='#', delimiter=None, create_using=None, encoding='utf-8')[source]

Read a file containing an incidence matrix 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:

A Hypergraph object

Examples

>>> import xgi
>>> # H = xgi.read_incidence_matrix("test.csv", delimiter=",")
xgi.readwrite.incidence.write_incidence_matrix(H, path, delimiter=' ', encoding='utf-8')[source]

Write a Hypergraph object to a file as an incidence matrix.

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_incidence_matrix(H, "test.csv", delimiter=",")