deepgraph.deepgraph.DeepGraph.return_cs_graph

DeepGraph.return_cs_graph(relations=False, dropna=True)

Return scipy.sparse.coo_matrix representation(s).

Create a compressed sparse graph representation for each type of relation given by relations. relations can either be False, True, or a (list of) column name(s) of e. If relations is False (default), return a single csgraph entailing all edges in e.index, each with a weight of 1 (in that case, dropna is discarded). If relations is True, create one csgraph for each column of e, where the weights are given by the columns’ values. If only a subset of columns is to be mapped to csgraphs, relations has to be a (list of) column name(s) of e.

The argument dropna indicates whether to discard edges with NA values or not. If dropna is True or False, it applies to all types of relations given by relations. However, dropna can also be array_like with the same shape as relations (or with the same shape as e.columns, if relations is True).

Parameters:
  • relations (bool, str or array_like, optional (default=False)) – The types of relations to be mapped to scipy csgraphs. Can be False, True, or a (list of) column name(s) of e.
  • dropna (bool or array_like, optional (default=True)) – Whether to drop edges with NA values. If True or False, applies to all relations given by relations. Otherwise, must be the same shape as relations. If relations is False, dropna is discarded.
Returns:

csgraph – A dictionary, where keys are column names of e, and values are the corresponding scipy.sparse.coo_matrix instance(s). If only one csgraph is created, return it directly.

Return type:

scipy.sparse.coo_matrix or dict

See also

return_nx_graph(), return_nx_multigraph(), return_gt_graph(), return_sparse_tensor()