简体   繁体   中英

Python - igraph find all vertices of specific category

hello I have following problem with libary igraph in python. I made a simple tree like that:

from igraph import *
import numpy as np

p = Graph(directed=True)
p.degree(mode='in')

p.add_vertices(2)
p.vs["label"] = ["Anna", "Peter"]
p.vs["category"] = np.full(2,1)


p.add_vertices(1)

p.vs[-1]["label"] = "Michael"
p.vs[-1]["category"] = -1

result = p.vs.find(category=1)["label"]

print(result)

with command p.vs.find(category=1)["label"] I want to find all vertices which have category same as 1. That means I expect a list ["Anna", "Peter"]. But for some reason my result only is:

Anna

how can I fix this?

Found answer by myself, just use

p.vs.select(category=1)["label"]

find only returns the first vertex of the vertex sequence.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM