Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
M = np.array(M)
if len(M.shape) != (2):
raise HyperNetXError('Input requires a 2 dimensional numpy array')
if node_names is not None:
nodenames = np.array(node_names)
if len(nodenames) != M.shape[0]:
raise HyperNetXError('Number of node names does not match number of rows.')
else:
nodenames = np.array([f'v{idx}' for idx in range(M.shape[0])])
if edge_names is not None:
edgenames = np.array(edge_names)
if len(edgenames) != M.shape[1]:
raise HyperNetXError('Number of edge_names does not match number of columns.')
else:
edgenames = np.array([f'e{jdx}' for jdx in range(M.shape[1])])
## apply boolean key if available
if key:
M = key(M)
## Remove empty column indices from M columns and edgenames
colidx = np.array([jdx for jdx in range(M.shape[1]) if any(M[:,jdx])])
colidxsum = np.sum(colidx)
if not colidxsum:
return Hypergraph()
else:
M = M[:,colidx]
edgenames = edgenames[colidx]
edict = dict()
If hypergraph is not s-edge-connected
Notes
-----
Two nodes are s-adjacent if they share s edges.
Two nodes v_start and v_end are s-walk connected if there is a sequence of
nodes v_start, v_1, v_2, ... v_n-1, v_end such that consecutive nodes
are s-adjacent. If the graph is not connected, an error will be raised.
"""
A = self.adjacency_matrix(s=s)
G = nx.from_scipy_sparse_matrix(A)
if nx.is_connected(G):
return nx.diameter(G)
else:
raise HyperNetXError(f'Hypergraph is not s-connected. s={s}')
If hypergraph is not s-edge-connected
Notes
-----
Two edges are s-adjacent if they share s nodes.
Two nodes e_start and e_end are s-walk connected if there is a sequence of
edges e_start, e_1, e_2, ... e_n-1, e_end such that consecutive edges
are s-adjacent. If the graph is not connected, an error will be raised.
"""
A = self.edge_adjacency_matrix(s=s)
G = nx.from_scipy_sparse_matrix(A)
if nx.is_connected(G):
return nx.diameter(G)
else:
raise HyperNetXError(f'Hypergraph is not s-connected. s={s}')
boolean function to be evaluated on each cell of the array
Returns
-------
: Hypergraph
Note
----
The constructor does not generate empty edges.
All-zero columns in df are removed and the names corresponding to these
edges are discarded.
'''
import pandas as pd
if type(df) != pd.core.frame.DataFrame:
raise HyperNetXError('Error: Input object must be a pandas dataframe.')
if transpose:
df = df.transpose()
node_names = np.array(df.index)
edge_names = np.array(df.columns)
df = df.fillna(fillna)
if key:
df = df.apply(key)
return cls.from_numpy_array(df.values,node_names=node_names,edge_names=edge_names,name=name)
All zero columns in M are removed and the names corresponding to these
edges are discarded.
"""
## Create names for nodes and edges
## Validate the size of the node and edge arrays
M = np.array(M)
if len(M.shape) != (2):
raise HyperNetXError('Input requires a 2 dimensional numpy array')
if node_names is not None:
nodenames = np.array(node_names)
if len(nodenames) != M.shape[0]:
raise HyperNetXError('Number of node names does not match number of rows.')
else:
nodenames = np.array([f'v{idx}' for idx in range(M.shape[0])])
if edge_names is not None:
edgenames = np.array(edge_names)
if len(edgenames) != M.shape[1]:
raise HyperNetXError('Number of edge_names does not match number of columns.')
else:
edgenames = np.array([f'e{jdx}' for jdx in range(M.shape[1])])
## apply boolean key if available
if key:
M = key(M)
## Remove empty column indices from M columns and edgenames
colidx = np.array([jdx for jdx in range(M.shape[1]) if any(M[:,jdx])])
: Hypergraph
Note
----
The constructor does not generate empty edges.
All zero columns in M are removed and the names corresponding to these
edges are discarded.
"""
## Create names for nodes and edges
## Validate the size of the node and edge arrays
M = np.array(M)
if len(M.shape) != (2):
raise HyperNetXError('Input requires a 2 dimensional numpy array')
if node_names is not None:
nodenames = np.array(node_names)
if len(nodenames) != M.shape[0]:
raise HyperNetXError('Number of node names does not match number of rows.')
else:
nodenames = np.array([f'v{idx}' for idx in range(M.shape[0])])
if edge_names is not None:
edgenames = np.array(edge_names)
if len(edgenames) != M.shape[1]:
raise HyperNetXError('Number of edge_names does not match number of columns.')
else:
edgenames = np.array([f'e{jdx}' for jdx in range(M.shape[1])])
## apply boolean key if available