Reshape Numpy Array: 'list' object is not callable












-2














I have a method, get_input_representation that returns a numpy array



np.array = input_stack + input_buffer 


return np.array


In another a different part of the program, I call the above method, save its return value and reshape it.



state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)


However, I get:




reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable




I have also tried:



 reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)


But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?










share|improve this question




















  • 2




    You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
    – hpaulj
    Nov 12 '18 at 4:18










  • even if np.array is in a different file from the caller function?
    – Matt
    Nov 12 '18 at 4:21










  • Don't use a name that could confuse you or the code.
    – hpaulj
    Nov 12 '18 at 4:55
















-2














I have a method, get_input_representation that returns a numpy array



np.array = input_stack + input_buffer 


return np.array


In another a different part of the program, I call the above method, save its return value and reshape it.



state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)


However, I get:




reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable




I have also tried:



 reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)


But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?










share|improve this question




















  • 2




    You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
    – hpaulj
    Nov 12 '18 at 4:18










  • even if np.array is in a different file from the caller function?
    – Matt
    Nov 12 '18 at 4:21










  • Don't use a name that could confuse you or the code.
    – hpaulj
    Nov 12 '18 at 4:55














-2












-2








-2







I have a method, get_input_representation that returns a numpy array



np.array = input_stack + input_buffer 


return np.array


In another a different part of the program, I call the above method, save its return value and reshape it.



state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)


However, I get:




reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable




I have also tried:



 reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)


But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?










share|improve this question















I have a method, get_input_representation that returns a numpy array



np.array = input_stack + input_buffer 


return np.array


In another a different part of the program, I call the above method, save its return value and reshape it.



state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)


However, I get:




reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable




I have also tried:



 reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)


But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?







python arrays numpy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 4:19

























asked Nov 12 '18 at 3:54









Matt

4871724




4871724








  • 2




    You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
    – hpaulj
    Nov 12 '18 at 4:18










  • even if np.array is in a different file from the caller function?
    – Matt
    Nov 12 '18 at 4:21










  • Don't use a name that could confuse you or the code.
    – hpaulj
    Nov 12 '18 at 4:55














  • 2




    You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
    – hpaulj
    Nov 12 '18 at 4:18










  • even if np.array is in a different file from the caller function?
    – Matt
    Nov 12 '18 at 4:21










  • Don't use a name that could confuse you or the code.
    – hpaulj
    Nov 12 '18 at 4:55








2




2




You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
– hpaulj
Nov 12 '18 at 4:18




You imported numpy as np. np.array is a function that is used to create a numpy array (class ndarray). But you then rename this np.array = .... Now it no longer is a function, but the result of that first line. The original np.array function is no longer available.
– hpaulj
Nov 12 '18 at 4:18












even if np.array is in a different file from the caller function?
– Matt
Nov 12 '18 at 4:21




even if np.array is in a different file from the caller function?
– Matt
Nov 12 '18 at 4:21












Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55




Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55












2 Answers
2






active

oldest

votes


















2














I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer and then return np.array you should have return input_stack + input_buffer in your function






share|improve this answer





























    0














    Would you need brackets instead of parens?



    np.array[state_rep].reshape(-1,6)


    I think you are trying to index into the np array right?






    share|improve this answer





















    • when i do this, i get TypeError: list indices must be integers or slices, not list
      – Matt
      Nov 12 '18 at 4:04










    • Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
      – LeKhan9
      Nov 12 '18 at 4:16










    • yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
      – Matt
      Nov 12 '18 at 4:19






    • 1




      You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
      – LeKhan9
      Nov 12 '18 at 4:21











    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',
    autoActivateHeartbeat: false,
    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%2f53255750%2freshape-numpy-array-list-object-is-not-callable%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer and then return np.array you should have return input_stack + input_buffer in your function






    share|improve this answer


























      2














      I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer and then return np.array you should have return input_stack + input_buffer in your function






      share|improve this answer
























        2












        2








        2






        I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer and then return np.array you should have return input_stack + input_buffer in your function






        share|improve this answer












        I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer and then return np.array you should have return input_stack + input_buffer in your function







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 4:24









        Piyush Singh

        865




        865

























            0














            Would you need brackets instead of parens?



            np.array[state_rep].reshape(-1,6)


            I think you are trying to index into the np array right?






            share|improve this answer





















            • when i do this, i get TypeError: list indices must be integers or slices, not list
              – Matt
              Nov 12 '18 at 4:04










            • Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
              – LeKhan9
              Nov 12 '18 at 4:16










            • yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
              – Matt
              Nov 12 '18 at 4:19






            • 1




              You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
              – LeKhan9
              Nov 12 '18 at 4:21
















            0














            Would you need brackets instead of parens?



            np.array[state_rep].reshape(-1,6)


            I think you are trying to index into the np array right?






            share|improve this answer





















            • when i do this, i get TypeError: list indices must be integers or slices, not list
              – Matt
              Nov 12 '18 at 4:04










            • Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
              – LeKhan9
              Nov 12 '18 at 4:16










            • yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
              – Matt
              Nov 12 '18 at 4:19






            • 1




              You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
              – LeKhan9
              Nov 12 '18 at 4:21














            0












            0








            0






            Would you need brackets instead of parens?



            np.array[state_rep].reshape(-1,6)


            I think you are trying to index into the np array right?






            share|improve this answer












            Would you need brackets instead of parens?



            np.array[state_rep].reshape(-1,6)


            I think you are trying to index into the np array right?







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 '18 at 4:01









            LeKhan9

            931112




            931112












            • when i do this, i get TypeError: list indices must be integers or slices, not list
              – Matt
              Nov 12 '18 at 4:04










            • Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
              – LeKhan9
              Nov 12 '18 at 4:16










            • yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
              – Matt
              Nov 12 '18 at 4:19






            • 1




              You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
              – LeKhan9
              Nov 12 '18 at 4:21


















            • when i do this, i get TypeError: list indices must be integers or slices, not list
              – Matt
              Nov 12 '18 at 4:04










            • Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
              – LeKhan9
              Nov 12 '18 at 4:16










            • yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
              – Matt
              Nov 12 '18 at 4:19






            • 1




              You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
              – LeKhan9
              Nov 12 '18 at 4:21
















            when i do this, i get TypeError: list indices must be integers or slices, not list
            – Matt
            Nov 12 '18 at 4:04




            when i do this, i get TypeError: list indices must be integers or slices, not list
            – Matt
            Nov 12 '18 at 4:04












            Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
            – LeKhan9
            Nov 12 '18 at 4:16




            Hm, so it seems you aren't passing an index to the array. Can you add more info about what self.extractor.get_input_representation(words, pos, state) and what that returns?
            – LeKhan9
            Nov 12 '18 at 4:16












            yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
            – Matt
            Nov 12 '18 at 4:19




            yes, get_input_representation returns a np array (see edited post, hopefully made more clear)
            – Matt
            Nov 12 '18 at 4:19




            1




            1




            You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
            – LeKhan9
            Nov 12 '18 at 4:21




            You shouldn't assign it to np.array, try just creating a basic variable like output_list or something and then returning that.
            – LeKhan9
            Nov 12 '18 at 4:21


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255750%2freshape-numpy-array-list-object-is-not-callable%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

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation