python - 在 igraph 中根据源/目标选择边

标签 python igraph

有没有一种简单的方法可以根据 igraph 中的源和目标选择/删除边?

本质上我用的是

g.es["source"] = [e.source for e in g.es]
g.es["target"] = [e.target for e in g.es]    
g.es["tuple"]  = [e.tuple  for e in g.es]        

g.es.select(target=root)

但我觉得应该有一种方法可以在不存储源/目标信息两次的情况下做到这一点。

最佳答案

只需使用 _source=whatever_target=whatever 作为 select 的关键字参数,例如:

g.es.select(_source=root)

或者,您可以使用图表的 incident 方法,它会为您提供边 ID 列表,而不是过滤后的 EdgeSeq 如果这更适合您的目的:

g.incident(root, mode="out")

关于python - 在 igraph 中根据源/目标选择边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14594009/

相关文章:

python - SGDClassifier.partial_fit 返回错误 "classes should include labels"

python - 将包含分组数据的 CSV 导入到 Pandas 数据框中

python - python3 上的 UnicodeDecodeError

python - 我尝试使用 exec_run 执行到容器中但不起作用

python - 保留文件描述符以防止 FD 耗尽

python - 为什么optimal_count没有给出正确的结果?

python - 使用python igraph库读取.net pajek文件

r - 以最小距离连接矩阵的两个坐标

删除未连接的节点 R igraph 或 ggnet

python - 使用 igraph for python 的共同邻居和优先依附分数矩阵