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?










share|improve this question
























  • 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










  • 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'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

















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?










share|improve this question
























  • 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










  • 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'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















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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:49









khelwood

29.5k74060




29.5k74060










asked Nov 10 at 22:39









Pumpkinpeach

145




145












  • 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










  • 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'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










  • 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












  • 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














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






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 23:30









        cricket_007

        77.2k1142106




        77.2k1142106






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues