TA Lib Python包装器仅长度为1的数组错误
代码:TA Lib Python包装器仅长度为1的数组错误,python,python-2.7,ta-lib,Python,Python 2.7,Ta Lib,代码: def macd(prices): print "Running MACD" prices = np.asarray(prices) print prices macd, macdsignal, macdhist = MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9) print "MACD "+macd 说明: 我试图在一个包含收盘价
def macd(prices):
print "Running MACD"
prices = np.asarray(prices)
print prices
macd, macdsignal, macdhist = MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
print "MACD "+macd
说明:
我试图在一个包含收盘价的Python列表上运行一些分析
我知道我必须在将列表移交给TA Lib之前转换列表,因为我已经看到了所有这样做的示例
但是,只有长度为1的数组才能转换为Python标量,这是由
实现的
我是这样导入talib模块的,就像在:
然而,这在社区中是不受欢迎的,今天我发现了原因。一个模块名称空间与其他模块名称空间碰撞,导致错误。这句话说得很好
所以我刚刚干净地导入了talib:
import talib
最终有效的代码是:
def macd(prices):
print "Running MACD"
prices = np.array(prices, dtype=float)
print prices
macd, macdsignal, macdhist = talib.MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
print "MACD "+macd
哦,天哪,我也有同样的问题。也许他们应该改变他们的例子,或者我在这里有什么错误吗?:)你救了我一个晚上,谢谢分享。我遇到了同样的问题。
def macd(prices):
print "Running MACD"
prices = np.array(prices, dtype=float)
print prices
macd, macdsignal, macdhist = talib.MACD(prices, fastperiod=12, slowperiod=26, signalperiod=9)
print "MACD "+macd