本文簡要介紹
networkx.utils.decorators.nodes_or_number
的用法。用法:
nodes_or_number(which_args)
裝飾器允許節點數量或節點容器。
使用這個裝飾器,指定的參數可以是一個數字或一個節點容器。如果是數字,則使用的節點是
range(n)
。這允許nx.complete_graph(50)
代替nx.complete_graph(list(range(50)))
。它還允許nx.complete_graph(any_list_of_nodes)
。- which_args:字符串或int 或字符串或整數序列
如果是字符串,則要處理的參數的名稱。如果是 int,則要處理的參數的索引。如果允許多個節點參數,則可以是位置列表。
- _nodes_or_numbers:函數
用範圍替換int args 的函數。
參數:
返回:
例子:
像這樣裝飾函數:
@nodes_or_number("nodes") def empty_graph(nodes): # nodes is converted to a list of nodes @nodes_or_number(0) def empty_graph(nodes): # nodes is converted to a list of nodes @nodes_or_number(["m1", "m2"]) def grid_2d_graph(m1, m2, periodic=False): # m1 and m2 are each converted to a list of nodes @nodes_or_number([0, 1]) def grid_2d_graph(m1, m2, periodic=False): # m1 and m2 are each converted to a list of nodes @nodes_or_number(1) def full_rary_tree(r, n) # presumably r is a number. It is not handled by this decorator. # n is converted to a list of nodes
相關用法
- Python NetworkX nodes_with_selfloops用法及代碼示例
- Python NetworkX node_attribute_xy用法及代碼示例
- Python NetworkX node_link_data用法及代碼示例
- Python NetworkX node_degree_xy用法及代碼示例
- Python NetworkX node_redundancy用法及代碼示例
- Python NetworkX node_connectivity用法及代碼示例
- Python NetworkX node_disjoint_paths用法及代碼示例
- Python NetworkX node_link_graph用法及代碼示例
- Python NetworkX not_implemented_for用法及代碼示例
- Python NetworkX non_randomness用法及代碼示例
- Python NetworkX negative_edge_cycle用法及代碼示例
- Python NetworkX numerical_edge_match用法及代碼示例
- Python NetworkX number_of_selfloops用法及代碼示例
- Python NetworkX numeric_assortativity_coefficient用法及代碼示例
- Python NetworkX np_random_state用法及代碼示例
- Python NetworkX naive_greedy_modularity_communities用法及代碼示例
- Python NetworkX numerical_multiedge_match用法及代碼示例
- Python NetworkX numerical_node_match用法及代碼示例
- Python NetworkX network_simplex用法及代碼示例
- Python NetworkX voronoi_cells用法及代碼示例
- Python NetworkX inverse_line_graph用法及代碼示例
- Python NetworkX LFR_benchmark_graph用法及代碼示例
- Python NetworkX write_graph6用法及代碼示例
- Python NetworkX DiGraph.__contains__用法及代碼示例
- Python NetworkX average_degree_connectivity用法及代碼示例
注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.utils.decorators.nodes_or_number。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。