是否可以在矢量或其他数据结构中存储一组图形(来自def ft_sum(tree, a, b):
if a == 0:
s = 0;
while b >= 0:
s += tree[b];
b = (b & (b + 1)) - 1
return s
return ft_sum(tree, 0, b) - ft_sum(tree, 0, a - 1)
def ft_adjust(tree, k, v):
while k < len(tree):
tree[k] += v
k |= k + 1
def calcI(P):
n = len(P)
tree = [0] * n
I = [0] * n
positions = [0] * n
for i in xrange(n):
positions[P[i]-1] = i
tree = [0] * n
for i in xrange(n):
pos = positions[i]
ft_adjust(tree, pos, 1)
num_seen = ft_sum(tree, 0, pos)
I[i] = pos - num_seen + 1
return I
)?
我试图以这种方式做到这一点:
igraph
但它不起作用。我收到了错误:
require('igraph')
g1 <- make_tree(10,3)
g2 <- make_tree(30,3)
gs <- c(g1,g2)
as.igraph(gs[1])
答案 0 :(得分:2)
您可以将它们存储在列表中:
gs <- list(g1,g2)
class(gs[[1]])
# [1] "igraph"
gs[[i]]
是igraph,您不需要在其上运行as.igraph
。
此外,根据文档,as.igraph
函数只能用于codeigraphHRG
个对象。