Similar function to to_scipy_sparse_matrix in Julia sparse matrices functions
Question: I would like to ask if there is equivalent function in **Julia** language and
its
[functions](http://docs.julialang.org/en/release-0.3/stdlib/arrays/?highlight=sparse#sparse-
matrices) for sparse matrices to
[to_scipy_sparse_matrix](https://networkx.github.io/documentation/latest/reference/generated/networkx.convert_matrix.to_scipy_sparse_matrix.html#networkx.convert_matrix.to_scipy_sparse_matrix)
in **networkx**.

I am looking for equivalent to calling this function in [eigenvector
centrality
algorithm](https://github.com/networkx/networkx/blob/master/networkx/algorithms/centrality/eigenvector.py#L206).

Is there possibility to run this function as stated above, in eigenvector
centrality link, in **Julia** to produce the same output ?

Thanks for any suggestions. I am struggling few hours with this and I am
unable to make any results.

**Edit:**

    
    
    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
    


Answer: Try (following OP Julia code):

    
    
    julia> triple(e,d) = (e.source.index,e.target.index,e.attributes[d])
    triple (generic function with 1 method)
    
    julia> M = sparse(map(collect,zip([triple(e,d) for e in edges(g1)]...))...,length(g1.vertices),length(g1.vertices))
        2x3 sparse matrix with 3 Float64 entries:
        [1, 2]  =  1.0
        [1, 3]  =  0.5
        [2, 3]  =  2.5
    

`triple` returns a (source,target,d-attribute) triple which might come-in
useful in other places as well.

The sparse matrix is created with the `sparse(I,J,D,rows,cols)` constructor
where `I,J,D` are all same length vectors and for each index `i` for them, the
matrix had a `D[i]` value at position `I[i],J[i]`.

If a symmetric weight matrix is needed, use the following:

    
    
    julia> M = M+M'
    3x3 sparse matrix with 6 Float64 entries:
        [2, 1]  =  1.0
        [3, 1]  =  0.5
        [1, 2]  =  1.0
        [3, 2]  =  2.5
        [1, 3]  =  0.5
        [2, 3]  =  2.5
    

