Analysing a graph returned from a function?
up vote
-1
down vote
favorite
I have a function My(n)
that takes input as n
and returns a graph. How do I use the graph returned from the function and find the number of edges for different n values ?
Function:
def My(n):
l= nx.Graph
....
....
... #Ommitted definitions as its too long
return nx.draw(l, with_labels = True)
I tried defining my function as a variable:
for example for n = 5
and my function My(n)
which returns a graph satisfying some properties.
B = My(5)
print(B.number_of_nodes())
I get
AttributeError: 'NoneType' object has no attribute 'number_of_nodes'
I guess because B
is a function and not a graph? How do I analyse the graph my function produces?
python python-3.x networkx
|
show 1 more comment
up vote
-1
down vote
favorite
I have a function My(n)
that takes input as n
and returns a graph. How do I use the graph returned from the function and find the number of edges for different n values ?
Function:
def My(n):
l= nx.Graph
....
....
... #Ommitted definitions as its too long
return nx.draw(l, with_labels = True)
I tried defining my function as a variable:
for example for n = 5
and my function My(n)
which returns a graph satisfying some properties.
B = My(5)
print(B.number_of_nodes())
I get
AttributeError: 'NoneType' object has no attribute 'number_of_nodes'
I guess because B
is a function and not a graph? How do I analyse the graph my function produces?
python python-3.x networkx
Evidently your functionMy
does not return a graph. It returnsNone
.
– khelwood
Nov 10 at 22:42
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
The error message says it returnsNone
, even if you think otherwise. From what you've posted,My
returns the return value ofnx.draw
. Did you check whatnx.draw
is supposed to return?
– khelwood
Nov 10 at 22:44
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54
|
show 1 more comment
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a function My(n)
that takes input as n
and returns a graph. How do I use the graph returned from the function and find the number of edges for different n values ?
Function:
def My(n):
l= nx.Graph
....
....
... #Ommitted definitions as its too long
return nx.draw(l, with_labels = True)
I tried defining my function as a variable:
for example for n = 5
and my function My(n)
which returns a graph satisfying some properties.
B = My(5)
print(B.number_of_nodes())
I get
AttributeError: 'NoneType' object has no attribute 'number_of_nodes'
I guess because B
is a function and not a graph? How do I analyse the graph my function produces?
python python-3.x networkx
I have a function My(n)
that takes input as n
and returns a graph. How do I use the graph returned from the function and find the number of edges for different n values ?
Function:
def My(n):
l= nx.Graph
....
....
... #Ommitted definitions as its too long
return nx.draw(l, with_labels = True)
I tried defining my function as a variable:
for example for n = 5
and my function My(n)
which returns a graph satisfying some properties.
B = My(5)
print(B.number_of_nodes())
I get
AttributeError: 'NoneType' object has no attribute 'number_of_nodes'
I guess because B
is a function and not a graph? How do I analyse the graph my function produces?
python python-3.x networkx
python python-3.x networkx
edited Nov 10 at 22:49
khelwood
29.3k74060
29.3k74060
asked Nov 10 at 22:39
Pumpkinpeach
145
145
Evidently your functionMy
does not return a graph. It returnsNone
.
– khelwood
Nov 10 at 22:42
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
The error message says it returnsNone
, even if you think otherwise. From what you've posted,My
returns the return value ofnx.draw
. Did you check whatnx.draw
is supposed to return?
– khelwood
Nov 10 at 22:44
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54
|
show 1 more comment
Evidently your functionMy
does not return a graph. It returnsNone
.
– khelwood
Nov 10 at 22:42
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
The error message says it returnsNone
, even if you think otherwise. From what you've posted,My
returns the return value ofnx.draw
. Did you check whatnx.draw
is supposed to return?
– khelwood
Nov 10 at 22:44
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54
Evidently your function
My
does not return a graph. It returns None
.– khelwood
Nov 10 at 22:42
Evidently your function
My
does not return a graph. It returns None
.– khelwood
Nov 10 at 22:42
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
The error message says it returns
None
, even if you think otherwise. From what you've posted, My
returns the return value of nx.draw
. Did you check what nx.draw
is supposed to return?– khelwood
Nov 10 at 22:44
The error message says it returns
None
, even if you think otherwise. From what you've posted, My
returns the return value of nx.draw
. Did you check what nx.draw
is supposed to return?– khelwood
Nov 10 at 22:44
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
If I understand correctly, I would suggest something like this
def buildGraph(n):
g = nx.Graph()
# add to g
return g
g = buildGraph(5)
nx.draw(g, with_labels = True)
Basically, the draw function isn't returning the Graph, it's displaying a window, and returning nothing
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If I understand correctly, I would suggest something like this
def buildGraph(n):
g = nx.Graph()
# add to g
return g
g = buildGraph(5)
nx.draw(g, with_labels = True)
Basically, the draw function isn't returning the Graph, it's displaying a window, and returning nothing
add a comment |
up vote
0
down vote
If I understand correctly, I would suggest something like this
def buildGraph(n):
g = nx.Graph()
# add to g
return g
g = buildGraph(5)
nx.draw(g, with_labels = True)
Basically, the draw function isn't returning the Graph, it's displaying a window, and returning nothing
add a comment |
up vote
0
down vote
up vote
0
down vote
If I understand correctly, I would suggest something like this
def buildGraph(n):
g = nx.Graph()
# add to g
return g
g = buildGraph(5)
nx.draw(g, with_labels = True)
Basically, the draw function isn't returning the Graph, it's displaying a window, and returning nothing
If I understand correctly, I would suggest something like this
def buildGraph(n):
g = nx.Graph()
# add to g
return g
g = buildGraph(5)
nx.draw(g, with_labels = True)
Basically, the draw function isn't returning the Graph, it's displaying a window, and returning nothing
answered Nov 10 at 23:30
cricket_007
76.8k1042106
76.8k1042106
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244128%2fanalysing-a-graph-returned-from-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Evidently your function
My
does not return a graph. It returnsNone
.– khelwood
Nov 10 at 22:42
It returns a graph when I run it.
– Pumpkinpeach
Nov 10 at 22:43
The error message says it returns
None
, even if you think otherwise. From what you've posted,My
returns the return value ofnx.draw
. Did you check whatnx.draw
is supposed to return?– khelwood
Nov 10 at 22:44
you return "nx.draw(l, with_labels = True)" . now that is a function, and functions translate to a single value. In this case, a None apparently. So, even though i presume nx.draw is responsible for drawing the graph, or taking an action that gets you to view a graph, it itself is still not a graph. It is a function with probably no return value, or None.
– Paritosh Singh
Nov 10 at 22:50
You're right. I get a none value. So how do I convert the value into a 'graph' that I can analyse? Can I say My(n) = nx.Graph()
– Pumpkinpeach
Nov 10 at 22:54