我想问一下在Julia语言中是否有等价的函数及其functions,用于稀疏矩阵到networkx的to_scipy_sparse_matrix的转换。
我正在寻找在eigenvector centrality algorithm中调用此函数的等效方法。
在Julia中是否有可能像在eigenvector centrality link中所述那样运行此函数以产生相同的输出?
感谢任何建议。 我已经花费了几个小时来解决这个问题,但是无法得出任何结果。 编辑:
我正在寻找在eigenvector centrality algorithm中调用此函数的等效方法。
在Julia中是否有可能像在eigenvector centrality link中所述那样运行此函数以产生相同的输出?
感谢任何建议。 我已经花费了几个小时来解决这个问题,但是无法得出任何结果。 编辑:
Python version :
import networkx as nx
import scipy
G = nx.Graph()
G.add_edge(1, 2, w=1.0 )
G.add_edge(1, 3, w=0.5 )
G.add_edge(2, 3, w=2.5 )
M = nx.to_scipy_sparse_matrix(G, nodelist=list(G), weight='w',dtype=float)
print(M)
Output:
(0, 1) 1.0
(0, 2) 0.5
(1, 0) 1.0
(1, 2) 2.5
(2, 0) 0.5
(2, 1) 2.5
Julia version:
using Graphs
g1 = Graphs.graph(Graphs.ExVertex[], Graphs.ExEdge{Graphs.ExVertex}[], is_directed=false)
d = "dist"
v1 = add_vertex!(g1, "a")
v2 = add_vertex!(g1, "b")
v3 = add_vertex!(g1, "c")
e12 = add_edge!(g1, v1, v2)
e12.attributes[d]=1.0
e13 = add_edge!(g1, v1, v3)
e13.attributes[d]=0.5
e23 = add_edge!(g1, v2, v3)
e23.attributes[d]=2.5
g
是一个图形,可以通过朴素的方式获取稀疏邻接矩阵,即使用Graphs.jl
库中的sparse(adjacency_matrix(g))
。 - Dan Getzsparse(weight_matrix(g1,map(x->x.attributes[d],edges(g1))))
会生成一个稀疏矩阵(但是首先需要经过密集表示)。 - Dan Getz