fix numpy 1.6 compatibility

This commit is contained in:
Gregory R. Lee
2015-12-22 16:45:51 -05:00
committed by Gregory R. Lee
parent 2d326a464e
commit c2b86d8a02
+6 -1
View File
@@ -175,7 +175,12 @@ def _denoise_tv_chambolle_nd(im, weight=0.2, eps=2.e-4, n_iter_max=200):
g[slices_g] = np.diff(out, axis=ax)
slices_g[ax] = slice(None)
norm = np.sqrt((g*g).sum(-1, keepdims=True))
try:
norm = np.sqrt((g*g).sum(-1, keepdims=True))
except:
# no keepdims argument available prior to numpy 1.7
norm = np.sqrt((g*g).sum(-1))[..., np.newaxis]
E += weight * norm.sum()
norm *= 0.5 / weight
norm += 1.