pythonfindigraphvertices

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?


Solution

  • Found answer by myself, just use

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

    find only returns the first vertex of the vertex sequence.