python列表add用法 使用add edge

2021-10-18 14:56:18 字數 1028 閱讀 6320

graph-tool行為與networkx不同。當您建立networkx節點時,它的識別符號是您在節點建構函式中編寫的,這樣您就可以通過節點的id來獲取該節點。在graph tool中,每個頂點id都是從1到graph\u size的整數:each vertex in a graph has an unique index, which is always between 0 and n−1, where n is the number of vertices. this index can be obtained by using the vertex_index attribute of the graph (which is a property map, see property maps), or by converting the vertex descriptor to an int.

關於圖、頂點或邊的所有附加資訊都儲存在property maps中。當您將.add_edge_list()與hashed=true一起使用時,新的屬性對映將作為.add_edge_list()的結果返回。所以在你的例子中,你應該像這樣處理你的頂點:# create graph

g = grt.graph(directed=false)

# create edge list

# why frozensets? you don't really need them. you can use ordinary sets or tuples

edge_list = ),

frozenset(),

frozenset()

# write returned propertymap to a variable!

vertex_ids = g.add_edge_list(edge_list, hashed=true, string_vals=true)

g.vertex(1)

out [...]:

vertex_ids[1]

out [...]: '56'

因此可以輕鬆獲得頂點索引:

^$

python列表常見用法

在了解python列表之前,我們先來簡單的了解一下python的序列和資料結構。基本概念 資料結構是以某種方式組合起來的資料元素集合 資料結構的家庭成員 列表list 元組tuple 字典dict 集合set 列表中的每個元素都可變的,意味著可以對每個元素進行修改和刪除 列表是有序的,每個元素的位置...

Python 列表使用

1.表的求長 2.下標表示式 3.表的構造 4.處理表的基本方法 5.表的巢狀 6.程式設計例項 7.表的操作 8.深淺拷貝 lst 1,2,3,4,5 len lst 5 lst 1,2,3,4,5 lst 0 1 lst 1 5 lst math phys econ lst 1 eng lst ...

python 列表 簡單用法

最近在做題的時候遇到了列表中的一些問題,簡單記錄一下 首先先簡單說一下迭代器的用法 s 1234 print iter s next 輸出 1 print iter s next 輸出 2 print iter s next 輸出 3可以簡單的說使用迭代器輸出時記錄下來了輸出的位置 iter s i...