igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] python-igraph data to numpy


From: Andreas Geiges
Subject: [igraph] python-igraph data to numpy
Date: Thu, 15 Feb 2018 17:19:40 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Dear Igraph users,

I am using python-igraph in python2.7 in combination with numpy.

I need to speed up the following scenario and was wondering if someone can give my some hints.
I have a large graph with several thousands of vertices.
One property of the vertices is a one-dimensional numpy array ( e.g. array([0,0,0,0]) )

If I read out the property of one vertice, I get the numpy array directly back, no conversion needed. But if I read the property of an vertice sequence, I get a list of array, which is perfectly fine. BUT I like to have the data as a 2D-array in numpy, thus I need to use numpy.asarray() which cause an overhead, which
cost me a lost of computing time form many of this operation.

Thus, I was wondering if there is a way, to directly receive a 2D-array back from igraph, when using a sequence.
I think this is not possible right now, but maybe it can be implemented.
I would be willing to try that, but I would need some hints, where to start.

The following code is maybe demonstrating better what I want to accomplish:

######################################
import igraph  as ig
import numpy as np
from  timeit import timeit as ti
#%%  Setup
graph = ig.Graph()

nVert = 1000
graph.add_vertices(nVert)

for vertice in graph.vs:
    vertice['property'] = np.random.random(5)
    #print vertice

#creation of a arbitray sequence
vertexSequence = graph.vs[np.arange(0,nVert,5).tolist()]

#%% reading the properties of a sequence to an numpy array


#first possiblity using asarray
%timeit numpyArray2D = np.asarray(vertexSequence['property'],dtype=np.float64)

#second possiblity with pre-allocated array and numpy view
numpyArray2D = np.zeros([len(vertexSequence),5])
%timeit numpyArray2D[:] = vertexSequence['property']
######################################

Any help or comments are welcome. Thanks a lot in advance!!!

Best,
Andreas

--
Dr.-Ing. Andreas Geiges

Global Climate Forum (GCF)
Neue Promenade 6, D-10178 Berlin, Germany
http://www.globalclimateforum.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]