mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-07 11:28:14 +08:00
Create helper function to compute norm along axis
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user