我在运行github代码时遇到错误。我认为代码是完美的,但我认为我正面临一些依赖性问题。任何人都可以告诉我可能是这个错误背后的原因。我正在使用python 2.7。
from __future__ import division, print_function
.
.
def time_step(self, xt):
xt = np.reshape(xt, newshape=self.dimensions)
ret_val = 0.
self.buffer.append(xt)
self.present.time_step(xt)
if self.t >= self.buffer_len:
pst_xt = self.buffer[0]
self.past.time_step(pst_xt)
if self.t >= self.present.theta + self.past.theta:
ret_val = self.comparison_function(self.present, self.past,
self.present.alpha)
self.ma_window.append(ret_val)
if self.t % self.ma_recalc_delay == 0:
self.anomaly_mean = bn.nanmean(self.ma_window)
self.anomaly_std = bn.nanstd(self.ma_window, ddof=self.ddof)
if self.anomaly_std is None or self.t < len(self.ma_window):
anomaly_density = 0
else:
normalized_score = (ret_val - self.anomaly_mean)/self.anomaly_std
if -4 <= normalized_score <= 4:
anomaly_density = CDF_TABLE[round(normalized_score, 3)]
elif normalized_score > 4:
anomaly_density = 1.
else:
anomaly_density = 0.
self.t += 1
return ret_val, anomaly_density
给出错误的代码行如下,
normalized_score = (ret_val - self.anomaly_mean)/self.anomaly_std
答案 0 :(得分:0)
将其包裹在try except
中,我使用0
作为值,但您可以根据需要更改它:
try:
normalized_score = (ret_val - self.anomaly_mean)/self.anomaly_std
except ZeroDivisionError:
normalized_score = 0