| 1 | initial version |
Hi,
This is a problem with Sage integers fighting with numpy integers
sage: A[2] == A[4]
False
sage: type(A[2])
<type 'sage.rings.integer.Integer'>
sage: type(A[4])
<type 'numpy.int64'>
You can solve the issue working only with Sage integers as follows
sage: M = matrix(6)
sage: M[0,2]=M[2,0]=M[2,3]=1
sage: M[3,2]=M[2,1]=M[1,2]=1
sage: M[4,5]=M[5,4]=1
sage: G = Graph(M)
sage: A = G.connected_component_containing_vertex(2)
sage: A
[0, 1, 2, 3]
(using networx is fine as well)
There is already an old ticket related to that problem on the Sage trac server: #13386: comparison of Sage integer with Numpy integer
Vincent
| 2 | No.2 Revision |
Hi,
This is a problem with Sage integers fighting with numpy integers
sage: A[2] == A[4]
False
sage: type(A[2])
<type 'sage.rings.integer.Integer'>
sage: type(A[4])
<type 'numpy.int64'>
You can solve the issue working only with Sage integers as follows
sage: M = matrix(6)
sage: M[0,2]=M[2,0]=M[2,3]=1
sage: M[3,2]=M[2,1]=M[1,2]=1
sage: M[4,5]=M[5,4]=1
sage: G = Graph(M)
sage: A = G.connected_component_containing_vertex(2)
sage: A
[0, 1, 2, 3]
(using networx is fine as well)
There is already an old ticket related to that problem on the Sage trac server: #13386: comparison of Sage integer with Numpy integer
EDIT: if you want to solve it on your example, use
sage: nx.node_connected_component(G, np.int(2))
[0, 1, 2, 3]
If you use only numpy and networkx, there is no need to use Sage. Just use the standard Ipython you will have less troubles.
Vincent
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.