xgi.convert.incidence

Methods for converting to and from an incidence matrix.

Functions

xgi.convert.incidence.from_incidence_matrix(d, create_using=None, nodelabels=None, edgelabels=None)[source]

Create a hypergraph from an incidence matrix

Parameters:
  • d (numpy array or a scipy sparse arrary) – The incidence matrix where rows specify nodes and columns specify edges.

  • create_using (Hypergraph constructor, optional) – The hypergraph object to add the data to, by default None

  • nodelabels (list or 1D numpy array, optional) – The ordered list of node IDs to map the indices of the incidence matrix to, by default None

  • edgelabels (list or 1D numpy array, optional) – The ordered list of edge IDs to map the indices of the incidence matrix to, by default None

Returns:

The constructed hypergraph

Return type:

Hypergraph object

Raises:

XGIError – Raises an error if the specified labels are the wrong dimensions

See also

incidence_matrix, to_incidence_matrix

xgi.convert.incidence.to_incidence_matrix(H, sparse=True, index=False)[source]

Convert a hypergraph to an incidence matrix.

Parameters:
  • H (Hypergraph object) – The hypergraph of interest

  • sparse (bool, optional) – Whether the constructed incidence matrix should be sparse, by default True

  • index (bool, optional) – Whether to return the corresponding node and edge labels, by default False

Returns:

  • numpy.ndarray or scipy csr_array – The incidence matrix

  • dict – The dictionary mapping indices to node IDs, if index is True

  • dict – The dictionary mapping indices to edge IDs, if index is True

See also

incidence_matrix, from_incidence_matrix