{"id":29456,"date":"2021-03-01T13:01:56","date_gmt":"2021-03-01T21:01:56","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=29456"},"modified":"2023-12-01T04:09:03","modified_gmt":"2023-12-01T12:09:03","slug":"python-numpy-ndarray-not-callable","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/","title":{"rendered":"Python &#8216;numpy.ndarray&#8217; object is not callable Solution"},"content":{"rendered":"\n<p>Like any regular Python array, you can access the contents of a NumPy array using indexing. The indexing method, which uses square brackets, lets you see one item in a list or a particular part of a list. If you try to retrieve an item from a NumPy array using round brackets, you will encounter an error.<br><\/p>\n\n\n\n<p>In this guide, we&#8217;re going to talk about what the <code>'numpy.ndarray' object is not callable<\/code> error means. We will then discuss an example scenario of this error in action and show you the solution. Let&#8217;s get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">&#8216;numpy.ndarray&#8217; object is not callable<\/h2>\n\n\n\n<p>The <code>'numpy.ndarray' object is not callable<\/code> Python error indicates you are trying to call a NumPy array as if it were a function. This happens if you use round brackets ( ) instead of square brackets [ ] to retrieve items from a list.<br><\/p>\n\n\n\n<p>The fix to this error is simple: you must replace ( ) with [ ] when you are indexing.<br><\/p>\n\n\n\n<p>In Python, square brackets indicate indexing whereas round brackets denote a function call. If you use round brackets while trying to access an item in an array, Python cannot handle your code because the array is not structured like a function.<br><\/p>\n\n\n\n<p>Let&#8217;s walk through an example of this error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">An Example Scenario<\/h2>\n\n\n\n<p>We are building a program that evaluates the grades of every student in a school. We want to calculate the average grade of each student.<br><\/p>\n\n\n\n<p>Each student&#8217;s grades are stored in a NumPy array like this:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import numpy as np\n\nstudent = np.array([72, 87, 80, 69, 91])<\/pre><\/div>\n\n\n\n<p>The final item indicates the grade a student received on their final exam. We want to print that grade individually to the console before we show the average grade of each student.<br><\/p>\n\n\n\n<p>To show the exam grade and average grade for each student, we could use this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>exam_grade = student(-1)\nprint(&quot;This student earned {} on their exam.&quot;.format(exam_grade))\n\naverage_grade = np.sum(student) \/ student.size\nprint(&quot;This student received an average {} mark on each test.&quot;.format(average_grade))<\/pre><\/div>\n\n\n\n<p>The first line of code finds the last item in our list. This item represents the mark a student received on their final exam. The next line displays the grade the student earned on their exam on the Python console. We then calculate the average grade the student earned and print that value to the console.<br><\/p>\n\n\n\n<p>Let&#8217;s run our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;\nTypeError: 'numpy.ndarray' object is not callable<\/pre><\/div>\n\n\n\n<p>Our code returns an error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Solution<\/h2>\n\n\n\n<p>When we try to access the last item in our student list, we use:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>exam_grade = student(-1)\nprint(&quot;This student earned {} on their exam.&quot;.format(exam_grade))<\/pre><\/div>\n\n\n\n<p>This line of code causes an error because you cannot use round brackets to access an item from a list. You must use square brackets. To fix our earlier code, we can replace the round brackets with square brackets:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>exam_grade = student[-1]\nprint(&quot;This student earned {} on their exam.&quot;.format(exam_grade))<\/pre><\/div>\n\n\n\n<p>Our code now returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>This student earned 91 on their exam.\nThis student received an average 79.8 mark on each test.<\/pre><\/div>\n\n\n\n<p>Our program retrieves the grade the student earned on their final exam. Then our program calculates the average grade a student received. Our program works as intended.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The Python <code>'numpy.ndarray' object is not callable<\/code> error is caused by using round brackets instead of square brackets to access an item from a NumPy array. To fix this error, use array_name[index_number] syntax to access an item from an array.<br><\/p>\n\n\n\n<p>Do you want to learn more about coding in Python? Read our <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-python\/\">How to Learn Python<\/a> guide. This guide contains expert learning advice to help you expand your knowledge of the Python programming language.<\/p>\n","protected":false},"excerpt":{"rendered":"Like any regular Python array, you can access the contents of a NumPy array using indexing. The indexing method, which uses square brackets, lets you see one item in a list or a particular part of a list. If you try to retrieve an item from a NumPy array using round brackets, you will encounter&hellip;","protected":false},"author":240,"featured_media":17673,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-29456","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python &#039;numpy.ndarray&#039; object is not callable Solution<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn the cause of and the solution to the Python &quot;&#039;numpy.ndarray&#039; object is not callable&quot; error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python &#039;numpy.ndarray&#039; object is not callable Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn the cause of and the solution to the Python &quot;&#039;numpy.ndarray&#039; object is not callable&quot; error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-01T21:01:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:09:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python &#8216;numpy.ndarray&#8217; object is not callable Solution\",\"datePublished\":\"2021-03-01T21:01:56+00:00\",\"dateModified\":\"2023-12-01T12:09:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\"},\"wordCount\":518,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\",\"name\":\"Python 'numpy.ndarray' object is not callable Solution\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg\",\"datePublished\":\"2021-03-01T21:01:56+00:00\",\"dateModified\":\"2023-12-01T12:09:03+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn the cause of and the solution to the Python \\\"'numpy.ndarray' object is not callable\\\" error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python &#8216;numpy.ndarray&#8217; object is not callable Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python 'numpy.ndarray' object is not callable Solution","description":"On Career Karma, learn the cause of and the solution to the Python \"'numpy.ndarray' object is not callable\" error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/","og_locale":"en_US","og_type":"article","og_title":"Python 'numpy.ndarray' object is not callable Solution","og_description":"On Career Karma, learn the cause of and the solution to the Python \"'numpy.ndarray' object is not callable\" error.","og_url":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2021-03-01T21:01:56+00:00","article_modified_time":"2023-12-01T12:09:03+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python &#8216;numpy.ndarray&#8217; object is not callable Solution","datePublished":"2021-03-01T21:01:56+00:00","dateModified":"2023-12-01T12:09:03+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/"},"wordCount":518,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/","url":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/","name":"Python 'numpy.ndarray' object is not callable Solution","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg","datePublished":"2021-03-01T21:01:56+00:00","dateModified":"2023-12-01T12:09:03+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn the cause of and the solution to the Python \"'numpy.ndarray' object is not callable\" error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/computers-cup-desk-gadgets-221011.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-numpy-ndarray-not-callable\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python &#8216;numpy.ndarray&#8217; object is not callable Solution"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/29456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=29456"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/29456\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/17673"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=29456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=29456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=29456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}