我写了一个小函数来获取一系列的日志返回:
def get_log_returns(series):
logs = numpy.log(series.astype('float64') / series.astype('float64').shift(1))
return logs
现在我想确保我只包含“合理”的日志。我知道我可以where
用来排除无穷大的日志:
def get_log_returns(series):
logs = numpy.log(series.astype('float64') / series.astype('float64').shift(1))
return logs.where(logs < numpy.inf)
但是,如果我想排除负面的日志怎么办?我希望这样的事情会起作用:
def get_log_returns(series):
logs = numpy.log(series.astype('float64') / series.astype('float64').shift(1))
return logs.where((logs < numpy.inf) and (logs > 0))
但这给了我一个
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
任何想法如何做到这一点?