TypeError: 'numpy.ndarray' object is not callable
Closed this issue · 4 comments
I encountered this error last week, which has stranded my progress.
I worry about it most likely being an environment or machine specific issue, and therefore not reproducible, because it is thrown due to a provided code block. I would therefore also like to show this image that shows what the result is on my own computer.
economics_notebook.zip
Indeed, I cannot replicate the error. When I run the code it works perfectly fine.
Are you running this on the university server?
You can actually simplify your code a bit (but I do not expect this to solve this issue):
def condition(x,p):
return x >= p
def demand(p,valuations):
number_of_agens = 0
return sum(condition(i,p) for i in valuations)
Can be simplified to:
def demand(p,valuations):
return np.sum(valuations>p)
stackoverflow suggests that the error is caused by calling the array as a function, but your current code does not do this. Perhaps it was there in a previous version?
Let me know what happens when you run the code on the university server.
Jan.
I am using jupyterlab.uvt.nl
What can I do to make sure it's running on the university server?
EDIT: As it turns out, changing the definition for the demand function does actually resolve the error. It must have been using it in a way that didn't account for the other implementation.
I will now attempt to catch up in the assignment, although I won't expect to be there by tomorrow morning.
Good to hear that things are resolved.
Just to be sure, can you run the following code on jupyterlab:
number_of_agents = 1000
number_of_goods = 100
valuations = np.array(sorted(pm.Normal.dist(100,20).random(size=number_of_agents),reverse = True))
def condition(x,p):
return x >= p
def demand(p,valuations):
number_of_agens = 0
return sum(condition(i,p) for i in valuations)
def excess_demand(p,valuations,number_of_goods):
return demand(p,valuations)-number_of_goods
price = optimize.fsolve(lambda x: excess_demand(x,valuations,number_of_goods),120)
print("{0: .2f}".format(price[0]))
This does not give any errors when I run it.
And you are lucky: there is no lecture tomorrow! You have a week to catch up ;)
Jan.
The code you posted also works fine