{"id":24588,"library":"similaritymeasures","title":"similaritymeasures","description":"Python library for quantifying the difference between two arbitrary curves in space. Provides implementations of common similarity measures including discrete Fréchet distance, dynamic time warping, curve length measure, area between two curves, and more. Current version 1.4.0, supports Python >=3.8, released under MIT license.","status":"active","version":"1.4.0","language":"python","source_language":"en","source_url":"https://github.com/cjekel/similarity_measures","tags":["curve-similarity","frechet-distance","dynamic-time-warping","area-between-curves","numpy","scipy"],"install":[{"cmd":"pip install similaritymeasures","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Required for all numerical operations","package":"numpy","optional":false},{"reason":"Required for Frechet distance (scipy.spatial.distance.cdist) and DTW","package":"scipy","optional":false}],"imports":[{"note":"Import the module itself; functions are accessed as similaritymeasures.frechet_dist(...)","symbol":"similaritymeasures","correct":"import similaritymeasures"},{"note":"frechet_dist is not a top-level import; must be accessed via the module","wrong":"frechet_dist","symbol":"Frechet distance function","correct":"similaritymeasures.frechet_dist"}],"quickstart":{"code":"import numpy as np\nimport similaritymeasures\n\n# Define two curves as arrays of (x, y) points\np = np.array([[1, 1], [2, 1], [3, 2]])\nq = np.array([[1, 1], [2, 3], [3, 2]])\n\n# Discrete Frechet distance\nfrechet = similaritymeasures.frechet_dist(p, q)\nprint(f\"Frechet distance: {frechet}\")\n\n# Dynamic time warping (DTW)\ndtw, d = similaritymeasures.dtw(p, q)\nprint(f\"DTW distance: {dtw}\")\n\n# Area between two curves\narea = similaritymeasures.area_between_two_curves(p, q)\nprint(f\"Area between curves: {area}\")\n\n# Curve length measure\nclm = similaritymeasures.curve_length_measure(p, q)\nprint(f\"Curve length measure: {clm}\")","lang":"python","description":"Demonstrates basic usage of main similarity measures"},"warnings":[{"fix":"Review area values if upgrading from <1.0.0; the new behavior is correct per the mathematical definition.","message":"In version 1.0.0, `area_between_two_curves` changed behavior for degenerate cases (e.g., repeating points or collinear points). The area may now differ from previous versions.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"If you need the old PCM results, call `similaritymeasures.pcm(p, q, norm_seg_length=True)`.","message":"In version 0.6.0, `similaritymeasures.pcm` changed outputs. To get previous behavior, set `norm_seg_length=True`.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Ensure both curves are numpy arrays with shape (n, 2) or (n, 3) for 3D.","message":"The functions expect inputs as 2D numpy arrays of shape (n, 2) for 2D curves. Passing lists or arrays of different shapes may cause errors or incorrect results.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import similaritymeasures` then `similaritymeasures.frechet_dist(...)`.","cause":"Attempting to import the function directly instead of the module.","error":"ImportError: cannot import name 'frechet_dist' from 'similaritymeasures'"},{"fix":"Ensure both curves have the same number of points, or use DTW which can handle different lengths.","cause":"Input curves have different number of points and not compatible for element-wise operations (e.g., `area_between_two_curves` requires equal lengths).","error":"ValueError: operands could not be broadcast together with shapes"},{"fix":"Convert your curves to numpy arrays: `p = np.array(p)` and `q = np.array(q)`.","cause":"Passing a list or tuple that isn't converted to numpy array, or ragged arrays.","error":"TypeError: only size-1 arrays can be converted to Python scalars"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}