From 50f2a0b4ed9c076d012480cf40837e0751002959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 4 Dec 2015 23:11:19 -0500 Subject: [PATCH] Create helper function to compute norm along axis --- skimage/measure/fit.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/skimage/measure/fit.py b/skimage/measure/fit.py index c6b6864b..b227d59f 100644 --- a/skimage/measure/fit.py +++ b/skimage/measure/fit.py @@ -15,6 +15,11 @@ def _check_data_atleast_2D(data): raise ValueError('Input data must be at least 2D.') +def _norm_along_axis(x, axis): + """NumPy < 1.8 does not support the `axis` argument for `np.linalg.norm`.""" + return np.sqrt(np.einsum('ij,ij->i', x, x)) + + class BaseModel(object): def __init__(self): @@ -239,8 +244,9 @@ class LineModelND(BaseModel): """ X0, u = self.params - return np.linalg.norm((data - X0) - - np.dot(data - X0, u)[..., np.newaxis] * u, axis=1) + return _norm_along_axis((data - X0) - + np.dot(data - X0, u)[..., np.newaxis] * u, + axis=1) def predict(self, x, axis=0, params=None): """Predict intersection of the estimated line model with a hyperplane