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