我第一次使用python + igraph 0.6并且有一些基本问题.
首先,我想制作一个随机图,然后在某处插入一个集团.
from igraph import *
g = Graph.Erdos_Renyi(50,0.1)
h = Graph.Full(5)
Run Code Online (Sandbox Code Playgroud)
如何通过两条边连接到图g来创建一个新的图g2?
其次,做完这个后,我想找到最大的派系并在图片中显示它们的位置.调用组合图g2.
mcliques = g2.maximal_cliques(4, 7)
Run Code Online (Sandbox Code Playgroud)
我现在如何单独或在图表g2中绘制我们刚刚发现的派系?
我正试图通过我的出版网络联系我的合作.我用的是igraph,它很棒.但是,由于我的顶点(代表我在网络中的那个)的边缘到所有共同作者,我最终得到了一个非常丰富的图形.我想从我的顶点删除边缘到一些只与另一位作者相关的作者.基本上是我只是共同创作的作者.无论如何,我已经确定了这些顶点,我知道我的顶点.现在我找不到一种方法来删除将这组边连接到我的边.
更一般地说,如何从两组矢量中去除边缘,例如V(g)[a]和V(g)[b]?
谢谢,
这是一个例子:
au1 <- c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'deb')
au2 <- c('art', 'deb', 'soy', 'deb', 'joy', 'ani', 'deb', 'deb', 'nem', 'mar')
au3 <- c('mar', 'lio', 'mil', 'mar', 'ani', 'lul', 'nem', 'art', 'deb', 'tat')
tata <- data.frame(au1, au2, au3)
xaulist2 <- levels(factor(unlist(tata[,])))
xaulist <- levels(as.factor(xaulist2))
xaulist_att <- c(rep('prime', 2), 'main', 'second', 'second', rep('prime', 3), 'second', rep('prime', 3))
au_att <- data.frame(au_name=xaulist, level=xaulist_att)
# matrix list preparation
tutu <- matrix(NA, nrow=length(xaulist), ncol=dim(tata)[1]) # row are authors …Run Code Online (Sandbox Code Playgroud) 自从我开始在我的编码中成功实现 Igraph 以来,我一直在想这个问题:你能用get_all_shortest_paths检索尽可能多的最短路径吗?让我们说前10个。
到目前为止,我已经理解在无向图中检索所有最短路径是没有意义的,因为在大多数情况下,您拥有无限数量的路径。
但是我可以简单地检索前 10 条最短路径吗?
我试图用无向 g = Graph() 来实现这一点:
list = []
list.append(g.get_all_shortest_paths(index1,index2, "distance")[0]) # shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[1]) # second shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[2]) # third shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[3]) # forth shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[4]) # fifth shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[5]) # sixth shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[6]) # seventh shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[7]) # eigth shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[8]) # ninth shortest path
list.append(g.get_all_shortest_paths(index1,index2, "distance")[9]) # tenth shortest path
#"distance" is from …Run Code Online (Sandbox Code Playgroud) 有谁知道我们如何使用python-igraph计算平均度分布?我认为它可能有一个功能,但我能找到的只是degree_distribution,它只返回节点度而不是平均值.
谢谢
我这样做.我一遍又一遍地得到同样的错误.提前致谢.
library(igraph)
library(sand)
zoo=read.csv("C:\\Documents and Settings\\kkk\\Desktop\\moo.data",header=FALSE)
a<-get.adjacency(moo)
**Error in get.adjacency(zoo) : Not a graph object**
V(moo)
**Error in V(moo) : Not a graph object**
Run Code Online (Sandbox Code Playgroud)
编辑评论的更多信息
我正在运行以下命令并获得以下错误.
library(igraph)
library(igraphdata)
library(sand)
zoo=read.csv("C:\\Documents and Settings\\kkk\\Desktop\\zoo.data",header=FALSE)
a <- get.adjacency(zoo)
# Error in get.adjacency(zoo) : Not a graph object
vcount(zoo)
# Error in vcount(zoo) : Not a graph object
Run Code Online (Sandbox Code Playgroud)
我怎么知道支持动物园数据的图形对象是什么
数据
第一个20 rows数据集zoo.(可从全部数据在这里有一个描述这里)
zoo <- structure(list(V1 = c("aardvark", "antelope", "bass", "bear",
"boar", "buffalo", "calf", "carp", "catfish", …Run Code Online (Sandbox Code Playgroud) 我正在尝试在R中运行osmar导航演示.这个演示将使用osmar和igraph绘制慕尼黑市中心周围的交通路线,基于openstreetmap数据.
我在Lubuntu上使用R版本3.1.1
演示和osmar库在这里详细介绍http://journal.r-project.org/archive/2013-1/eugster-schlesinger.pdf
要运行我输入的演示,
library("osmar")
library("igraph") # The demo tries to call igraph0, but this is
# no-longer available in my version of R, so I
# have changed it to "igraph"
demo("navigator")
Run Code Online (Sandbox Code Playgroud)
演示完美运行,直到它到达igraph部分.
gr_muc<-as_igraph(hways_muc) # make a graph of the highways from openstreetmap
summary(gr_muc)
Run Code Online (Sandbox Code Playgroud)
这应该回来了
Vertices: 2381
Edges: 2888
Directed: TRUE
No graph attributes.
Vertex attributes: name.
Edge attributes: weight, name.
Run Code Online (Sandbox Code Playgroud)
但对我来说它会回归
IGRAPH DNW-2385 2894 --
attr: name (v/c), weight (e/n), name (e/n)
Run Code Online (Sandbox Code Playgroud)
我知道这gr_muc是一个图形,因为边和顶点的命令E(gr_muc)和 …
我在Linux Mint(平台i686-pc-linux-gnu)上安装了R 3.4.1,但以前的R版本以及Windows都发生了同样的问题。当我尝试安装igraph使用install.packages(),这个错误发生的情况:
foreign-graphml.c: In function ‘igraph_write_graph_graphml’:
foreign-graphml.c:1408:46: error: expected ‘)’ before ‘GRAPHML_NAMESPACE_URI’
ret=fprintf(outstream, "<graphml xmlns=\"" GRAPHML_NAMESPACE_URI "\"\n");
^
foreign-graphml.c:1412:59: error: expected ‘)’ before ‘GRAPHML_NAMESPACE_URI’
ret=fprintf(outstream, " xsi:schemaLocation=\"" GRAPHML_NAMESPACE_URI "\n");
^
foreign-graphml.c:1414:38: error: expected ‘)’ before ‘GRAPHML_NAMESPACE_URI’
ret=fprintf(outstream, " " GRAPHML_NAMESPACE_URI "/1.0/graphml.xsd\">\n");
^
/usr/lib/R/etc/Makeconf:159: recipe for target 'foreign-graphml.o' failed
make: *** [foreign-graphml.o] Error 1
ERROR: compilation failed for package ‘igraph’
* removing ‘/home/ninja/R/i686-pc-linux-gnu-library/3.4/igraph’
Warning in install.packages :
installation of package ‘igraph’ had non-zero exit status
Run Code Online (Sandbox Code Playgroud)
我也尝试使用类似的方法从github安装: …
我开始在 C 中学习 igraph,我想知道如何可视化用这个库制作的图形。我已经看到使用 igraph R 只需使用 plot 函数并绘制图形,但是如果我使用 C,我应该在文件中打印图形,然后使用另一个程序将其可视化还是通常的方法?
谢谢!
编辑:这种图表。
我正在使用Docker构建应用程序。我的Dockerfile看起来像这样:
FROM python:3.7.0
WORKDIR /app
COPY . /app
RUN apt-get -y update && apt-get -y install apt-utils build-essential libxml2-dev zlib1g-dev python-dev python-pip pkg-config libffi-dev libcairo-dev
RUN pip install -r requirements.txt
CMD ["./run"]
Run Code Online (Sandbox Code Playgroud)
我的项目结构:
.
??? Dockerfile
??? requirements.txt
??? run
??? src
??? stuff
Run Code Online (Sandbox Code Playgroud)
在要求,我把plotly,pytest和python-igraph。问题是,python-igraph卡在这部分上
Running setup.py bdist_wheel for python-igraph: started
Running setup.py bdist_wheel for python-igraph: still running...
Run Code Online (Sandbox Code Playgroud)
在相当长的一段时间内,但最终它会拉取数据并生成图像。但是,如此长时间每次重建项目都是不可接受的。
提取彼此不依赖的模块的正确方法是什么?
或任何其他不可解析的表达式,如igraph::graph_from_literal(1A +--+ 1B).
函数调用quote(1A-2B)给出Error: unexpected symbol in quote(1A".
如何获得类似的结果
我正在寻找一种基于至少一个入射在该边缘上的顶点的顶点属性得分的子图边缘的方法.
有一个简单的方法吗?
有什么建议?
这是我的Dijkstra数据矩阵.注意:未直接链接的两个节点i和j之间的距离已设置为NA.
node X1 X2 X3 X4 X5 X6
[1,] 1 0 3 7 4 NA NA
[2,] 2 3 0 2 NA NA 9
[3,] 3 7 2 0 1 3 6
[4,] 4 4 NA 1 0 3 NA
[5,] 5 NA NA 3 3 0 3
[6,] 6 NA 9 6 NA 3 0
Run Code Online (Sandbox Code Playgroud)
我需要编写一个代码,提供从节点1到节点N的最短距离(因此只需要一个数字输出,而不是最短路径).该程序还应该在csv文件上工作,该文件包含任意维度的对称方形直接距离矩阵,任意数量的节点编号为1 ... N,以及矩阵中的任何正距离值.(您的程序将在此类矩阵上进行测试.)程序应输出从节点1到节点N的最短距离.
我试过:创建临时矩阵L(0)
l0data<-c(1,MatrixData[[1,1]],"Temp",2,MatrixData[[1,2]],"Temp",3,MatrixData[[1,3]],"Temp",4 ,MatrixData[[1,4]],"Temp",5, MatrixData[[1,5]],"Temp",6, MatrixData[[1,6]],"Temp")
l0<-matrix(l0data,nrow = 3, ncol = 6)
temp0<-l0[3,]=="Temp"
Run Code Online (Sandbox Code Playgroud)
选择值和L(0)的节点以使其成为永久性的
l0SelectVal<-l0[2,temp0]
#select nodes of temporary l0
l0SelectNod<-l0[1,temp0]
Run Code Online (Sandbox Code Playgroud)
答案最小值L(0) …