'numpy.ndarray'对象不可调用错误 [英] 'numpy.ndarray' object is not callable error
问题描述
我收到以下错误消息
'numpy.ndarray'对象不可调用
'numpy.ndarray' object is not callable
以以下方式执行计算时
rolling_means = pd.rolling_mean(prices,20,min_periods=20)`
rolling_std = pd.rolling_std(prices, 20)`
#print rolling_means.head(20)
upper_band = rolling_means + (rolling_std)* 2
lower_band = rolling_means - (rolling_std)* 2
我不确定如何解决,有人可以向我指出正确的方向....
I am not sure how to resolve, can someone point me in right direction....
推荐答案
错误TypeError: 'numpy.ndarray' object is not callable
表示您试图将numpy数组作为函数调用.我们可以在repl中重现这样的错误:
The error TypeError: 'numpy.ndarray' object is not callable
means that you tried to call a numpy array as a function. We can reproduce the error like so in the repl:
In [16]: import numpy as np
In [17]: np.array([1,2,3])()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/user/<ipython-input-17-1abf8f3c8162> in <module>()
----> 1 np.array([1,2,3])()
TypeError: 'numpy.ndarray' object is not callable
如果我们假设错误确实来自您发布的代码片段(应检查的内容),那么您必须在您的早期将pd.rolling_mean
或pd.rolling_std
重新分配给一个numpy数组代码.
If we are to assume that the error is indeed coming from the snippet of code that you posted (something that you should check,) then you must have reassigned either pd.rolling_mean
or pd.rolling_std
to a numpy array earlier in your code.
我的意思是这样的:
In [1]: import numpy as np
In [2]: import pandas as pd
In [3]: pd.rolling_mean(np.array([1,2,3]), 20, min_periods=5) # Works
Out[3]: array([ nan, nan, nan])
In [4]: pd.rolling_mean = np.array([1,2,3])
In [5]: pd.rolling_mean(np.array([1,2,3]), 20, min_periods=5) # Doesn't work anymore...
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/user/<ipython-input-5-f528129299b9> in <module>()
----> 1 pd.rolling_mean(np.array([1,2,3]), 20, min_periods=5) # Doesn't work anymore...
TypeError: 'numpy.ndarray' object is not callable
因此,基本上,您需要在代码库的其余部分中搜索pd.rolling_mean = ...
和/或pd.rolling_std = ...
,以查看可能覆盖了它们的位置.
So, basically you need to search the rest of your codebase for pd.rolling_mean = ...
and/or pd.rolling_std = ...
to see where you may have overwritten them.
另外,如果您愿意,可以放入
reload(pd)
紧接在您的代码片段之前,这应该通过将pd
的值恢复为最初导入时的值来使其运行,但是我仍然高度建议您尝试查找可能的位置已经重新分配了给定的功能.
Also, if you'd like, you can put in
reload(pd)
just before your snippet, which should make it run by restoring the value of pd
to what you originally imported it as, but I still highly recommend that you try to find where you may have reassigned the given functions.
这篇关于'numpy.ndarray'对象不可调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!