[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] Problem with Graph.Adjacency

**From**: |
Tamas Nepusz |

**Subject**: |
Re: [igraph] Problem with Graph.Adjacency |

**Date**: |
Wed, 24 Feb 2010 23:59:48 +0000 |

Dear Jonathan,
>* On my local MacBook, it works when a.dtype = "int32". However, on our 64bit *
>* Linux cluster, only a.dtype = "float64" works, wasting a lot of memory.*
>* *
>* Do you have any idea, what could be the cause of this issue?*
Please note that list(a) does not convert a 2D NumPy array into a proper list
of lists (what igraph.Graph.Adjacency requires), it converts the matrix into a
list of 1D NumPy arrays:
In [1]: import numpy as np
In [2]: a=np.array([[1,0,1], [0,1,0], [1,0,1]], dtype="int8")
In [3]: list(a)
Out[3]:
[array([1, 0, 1], dtype=int8),
array([0, 1, 0], dtype=int8),
array([1, 0, 1], dtype=int8)]
What you need is a.tolist():
In [4]: a.tolist()
Out[4]: [[1, 0, 1], [0, 1, 0], [1, 0, 1]]
In [5]: g = igraph.Graph.Adjacency(a.tolist())
In [6]: summary(g)
3 nodes, 5 edges, directed
Number of components: 2
Diameter: 1
Density: 0.8333
Reciprocity: 1.0000
Average path length: 1.0000
--
Tamas