[英]How to find number of nodes connected to two nodes in a graph?
I have a direct graph with the following adjacency matrix我有一个具有以下邻接矩阵的直接图
as.matrix(read.table(header=T, text=
" A B C D E F
A 0 1 0 0 0 1
B 0 0 0 0 0 1
C 0 1 0 0 1 0
D 0 1 0 0 1 1
E 0 0 0 0 0 1
F 0 0 0 0 0 0"))
I want to do some matrix manipulation that can give me the number of unique nodes that follow two nodes.我想做一些矩阵操作,可以给我跟随两个节点的唯一节点的数量。 For example in the previous matrix the result should be
例如在前面的矩阵中,结果应该是
A B C D E F
A|0 3 0 0 2 4|
B|3 3 3 3 3 5|
C|0 3 0 0 2 4|
D|0 3 0 0 2 4|
E|2 3 2 2 2 5|
F|4 5 4 4 5 4|
I'm using R for my coding.我正在使用 R 进行编码。 That would be great if somebody can help on that
如果有人可以提供帮助,那就太好了
I found the answer, I share it as it might be useful:我找到了答案,我分享它,因为它可能有用:
D<-colSums(A)
B<-matrix(D,ncol=length(D),nrow=length(D))
Result<-B+t(B)-t(A)%*%A
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.