Python Forum
numpy.ndarray' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy.ndarray' object is not callable
#1
Hi,

I'm new to python and I'm trying to call a function and use it to calculate the median of a dataset but when I run it I get the following error:
if n % 2 == 0:
    a_median = a(n / 2) + a((n / 2) -1) / 2
else:
    a_median = a[n//2]
Error:
TypeError: 'numpy.ndarray' object is not callable
I have tried to look about online to resolve this and I can see that it's something relating to calling an array as a function, but I don't know what that means or how to fix it.
Reply
#2
To call an object in python you use (), a ndarray is not a callable object, use [] instead.
Reply
#3
(Oct-11-2020, 06:42 PM)Yoriz Wrote: To call an object in python you use (), a ndarray is not a callable object, use [] instead.

Thanks for getting back to me. I'm really not sure where I'm meant to put the "[]" brackets. I've tried multiple different places (including all of them on the line with the equation) but then I get an error reading

"IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices"

Again, I'm very new to all of this so apologies if I'm missing something glaringly obvious.
Reply
#4
In line 2 replace every open paren with an open bracket, and every close paren with a close bracket.
Reply
#5
@natareid

numpy.median(arr, axis = None)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 537 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,599 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  'numpy.ndarray' object is not callable ato_cr 1 15,222 May-12-2020, 08:12 AM
Last Post: anbu23
  numpy.float64 object is not iterable jcdr91 1 13,215 Apr-22-2020, 04:09 PM
Last Post: jefsummers
  What is the mechanism of numpy function returning pandas object? Ibaraki 2 2,494 Apr-04-2020, 10:57 PM
Last Post: Ibaraki
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,976 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020