MCPcopy Create free account
hub / github.com/alibaba/GraphScope / empty_graph

Function empty_graph

python/graphscope/nx/generators/classic.py:207–253  ·  view source on GitHub ↗

Returns the empty graph with n nodes and zero edges. Parameters ---------- n : int or iterable container of nodes (default = 0) If n is an integer, nodes are from `range(n)`. If n is a container of nodes, those nodes appear in the graph. create_using : Graph Instance

(n=0, create_using=None, default=nx.Graph, **kw)

Source from the content-addressed store, hash-verified

205
206@nodes_or_number(0)
207def empty_graph(n=0, create_using=None, default=nx.Graph, **kw):
208 """Returns the empty graph with n nodes and zero edges.
209
210 Parameters
211 ----------
212 n : int or iterable container of nodes (default = 0)
213 If n is an integer, nodes are from `range(n)`.
214 If n is a container of nodes, those nodes appear in the graph.
215 create_using : Graph Instance, Constructor or None
216 Indicator of type of graph to return.
217 If a Graph-type instance, then clear and use it.
218 If None, use the `default` constructor.
219 If a constructor, call it to create an empty graph.
220 default : Graph constructor (optional, default = nx.Graph)
221 The constructor to use if create_using is None.
222 If None, then nx.Graph is used.
223 This is used when passing an unknown `create_using` value
224 through your home-grown function to `empty_graph` and
225 you want a default constructor other than nx.Graph.
226
227 Examples
228 --------
229 >>> G = nx.empty_graph(10)
230 >>> G.number_of_nodes()
231 10
232 >>> G.number_of_edges()
233 0
234 >>> G = nx.empty_graph("ABC")
235 >>> G.number_of_nodes()
236 3
237 >>> sorted(G)
238 ['A', 'B', 'C']
239
240 """
241 if create_using is None:
242 G = default(**kw)
243 elif hasattr(create_using, "_adj"):
244 # create_using is a NetworkX style Graph
245 create_using.clear()
246 G = create_using
247 else:
248 # try create_using as constructor
249 G = create_using(**kw)
250
251 n_name, nodes = n
252 G.add_nodes_from(nodes)
253 return G
254
255
256@patch_docstring(nxa.ladder_graph)

Callers 15

make_small_graphFunction · 0.90
LCF_graphFunction · 0.90
sedgewick_maze_graphFunction · 0.90
fast_gnp_random_graphFunction · 0.90
dense_gnm_random_graphFunction · 0.90
random_regular_graphFunction · 0.90
powerlaw_cluster_graphFunction · 0.90
random_shell_graphFunction · 0.90
grid_2d_graphFunction · 0.90

Calls 2

add_nodes_fromMethod · 0.80
clearMethod · 0.65

Tested by

no test coverage detected