1 | initial version |
You can simply call the method .networkx_graph();
sage: import networkx as nx
sage: G = graphs.PetersenGraph()
sage: ng = G.networkx_graph()
sage: ng
<networkx.classes.graph.Graph object at 0xd3c2f8c>
sage: nx.double_edge_swap(ng)
1
Incidentally, I didn't know this five minutes ago, so I should tell you how I found out. Lots of functionality in Sage objects lives inside them, in methods. Typically conversion functions are either called ".targettype" or "._targettype_", so I tried
sage: G.netw[HERE I HIT TAB]
G.networkx_graph
which looked promising. And then typing
sage: G.networkx_graph?
gives the documentation:
Help on method networkx_graph in module sage.graphs.generic_graph:
networkx_graph(self, copy=True) method of sage.graphs.graph.Graph instance
Creates a new NetworkX graph from the Sage graph.
INPUT:
- ``copy`` - if False, and the underlying
implementation is a NetworkX graph, then the actual object itself
is returned.
EXAMPLES::
sage: G = graphs.TetrahedralGraph()
sage: N = G.networkx_graph()
sage: type(N)
<class 'networkx.classes.graph.Graph'>
[etc.]
PS: Okay, to be perfectly honest, I tried it first and only looked at the documentation when I came to write this. But I would've looked at the documentaion if it hadn't worked, I promise! :^)
2 | No.2 Revision |
You can simply call the method .networkx_graph();.networkx_graph():
sage: import networkx as nx
sage: G = graphs.PetersenGraph()
sage: ng = G.networkx_graph()
sage: ng
<networkx.classes.graph.Graph object at 0xd3c2f8c>
sage: nx.double_edge_swap(ng)
1
Incidentally, I didn't know this five minutes ago, so I should tell you how I found out. Lots of functionality in Sage objects lives inside them, in methods. Typically conversion functions are either called ".targettype" or "._targettype_", so I tried
sage: G.netw[HERE I HIT TAB]
G.networkx_graph
which looked promising. And then typing
sage: G.networkx_graph?
gives the documentation:
Help on method networkx_graph in module sage.graphs.generic_graph:
networkx_graph(self, copy=True) method of sage.graphs.graph.Graph instance
Creates a new NetworkX graph from the Sage graph.
INPUT:
- ``copy`` - if False, and the underlying
implementation is a NetworkX graph, then the actual object itself
is returned.
EXAMPLES::
sage: G = graphs.TetrahedralGraph()
sage: N = G.networkx_graph()
sage: type(N)
<class 'networkx.classes.graph.Graph'>
[etc.]
PS: Okay, to be perfectly honest, I tried it first and only looked at the documentation when I came to write this. But I would've looked at the documentaion if it hadn't worked, I promise! :^)
3 | No.3 Revision |
You can simply call the method .networkx_graph():
sage: import networkx as nx
sage: G = graphs.PetersenGraph()
sage: ng = G.networkx_graph()
sage: ng
<networkx.classes.graph.Graph object at 0xd3c2f8c>
sage: nx.double_edge_swap(ng)
1
Incidentally, I didn't know this five minutes ago, so I should tell you how I found out. Lots of functionality in for Sage objects lives inside them, in methods. Typically conversion functions are either called ".targettype" or "._targettype_", so I tried
sage: G.netw[HERE I HIT TAB]
G.networkx_graph
which looked promising. And then typing
sage: G.networkx_graph?
gives the documentation:
Help on method networkx_graph in module sage.graphs.generic_graph:
networkx_graph(self, copy=True) method of sage.graphs.graph.Graph instance
Creates a new NetworkX graph from the Sage graph.
INPUT:
- ``copy`` - if False, and the underlying
implementation is a NetworkX graph, then the actual object itself
is returned.
EXAMPLES::
sage: G = graphs.TetrahedralGraph()
sage: N = G.networkx_graph()
sage: type(N)
<class 'networkx.classes.graph.Graph'>
[etc.]
PS: Okay, to be perfectly honest, I tried it first and only looked at the documentation when I came to write this. But I would've looked at the documentaion documentation if it hadn't worked, I promise! :^)
4 | No.4 Revision |
You can simply call the method .networkx_graph():
sage: import networkx as nx
sage: G = graphs.PetersenGraph()
sage: ng = G.networkx_graph()
sage: ng
<networkx.classes.graph.Graph object at 0xd3c2f8c>
sage: nx.double_edge_swap(ng)
1
Incidentally, I didn't know this five minutes ago, so I should tell you how I found out. Lots of functionality for Sage objects lives inside them, in methods. Typically conversion functions are either called ".targettype" or "._targettype_", so I tried
sage: G.netw[HERE I HIT TAB]
G.networkx_graph
which looked promising. And then typing
sage: G.networkx_graph?
gives the documentation:
Help on method networkx_graph in module sage.graphs.generic_graph:
networkx_graph(self, copy=True) method of sage.graphs.graph.Graph instance
Creates a new NetworkX graph from the Sage graph.
INPUT:
- ``copy`` - if False, and the underlying
implementation is a NetworkX graph, then the actual object itself
is returned.
EXAMPLES::
sage: G = graphs.TetrahedralGraph()
sage: N = G.networkx_graph()
sage: type(N)
<class 'networkx.classes.graph.Graph'>
[etc.]
PS: Okay, to be perfectly honest, I tried it first and only looked at the documentation when I came to write this. But I would've looked at the documentation if it hadn't worked, I promise! :^)
5 | No.5 Revision |
You can simply call the method .networkx_graph():
sage: import networkx as nx
sage: G = graphs.PetersenGraph()
sage: ng = G.networkx_graph()
sage: ng
<networkx.classes.graph.Graph object at 0xd3c2f8c>
sage: nx.double_edge_swap(ng)
1
Incidentally, I didn't know this five minutes ago, so I should tell you how I found out. Lots of functionality for Sage objects lives inside them, in methods. Typically conversion functions are either called ".targettype" or "._targettype_", so I tried
sage: G.netw[HERE I HIT TAB]
G.networkx_graph
which looked promising. And then typing
sage: G.networkx_graph?
gives the documentation:
Creates a new NetworkX graph from the Sage graph.
INPUT:
- ``copy`` * "copy" - if False, and the underlying
underlying implementation is a a
NetworkX graph, then the actual object itself
itself is returned.
EXAMPLES::
EXAMPLES:
sage: G = graphs.TetrahedralGraph()
sage: N = G.networkx_graph()
sage: type(N)
<class 'networkx.classes.graph.Graph'>
[etc.]
sage: G = graphs.TetrahedralGraph()
sage: G = Graph(G, implementation='networkx')
sage: N = G.networkx_graph()
sage: G._backend._nxg is N
False
sage: G = Graph(graphs.TetrahedralGraph(), implementation='networkx')
sage: N = G.networkx_graph(copy=False)
sage: G._backend._nxg is N
True
PS: Okay, to be perfectly honest, I tried it first and only looked at the documentation when I came to write this. But I would've looked at the documentation if it hadn't worked, I promise! :^)