{"id":23091,"library":"fastcluster","title":"fastcluster","description":"Fast hierarchical clustering routines for R and Python. Provides efficient implementations of hierarchical clustering (e.g., single, complete, average linkage) with memory-saving algorithms. Current version 1.3.0, with an irregular release cadence (last release 2022).","status":"active","version":"1.3.0","language":"python","source_language":"en","source_url":"https://github.com/dmuellner/fastcluster","tags":["hierarchical-clustering","bioinformatics","data-analysis","distance-matrix","linkage"],"install":[{"cmd":"pip install fastcluster","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Required for array operations","package":"numpy","optional":false},{"reason":"Provides distance functions and linkage consistency","package":"scipy","optional":true}],"imports":[{"note":"Direct import of function is idiomatic","wrong":"import fastcluster; fastcluster.linkage()","symbol":"fastcluster.linkage","correct":"from fastcluster import linkage"},{"note":"Used for vectorized input","wrong":null,"symbol":"linkage_vector","correct":"from fastcluster import linkage_vector"},{"note":"Precomputed linkage methods","wrong":null,"symbol":"single","correct":"from fastcluster import single"}],"quickstart":{"code":"import numpy as np\nfrom fastcluster import linkage\n# Generate random data: 100 points in 3D\nX = np.random.rand(100, 3)\n# Perform hierarchical clustering with average linkage\nZ = linkage(X, method='average')\nprint(Z.shape)  # (99, 4)","lang":"python","description":"Basic usage: create random data, compute linkage matrix using average method."},"warnings":[{"fix":"Use method='ward' for Ward linkage. If you need weighted or centroid methods, note they may differ from scipy.","message":"The 'method' argument uses lowercase names (e.g., 'single', 'complete', 'average') — not 'ward' without the 'ward_D2' distinction that scipy uses. fastcluster's 'ward' is equivalent to scipy's 'ward' (i.e., ward's method on Euclidean distances only, not on precomputed distances).","severity":"gotcha","affected_versions":"all"},{"fix":"Use scipy.spatial.distance.squareform to convert square matrix to condensed form before passing to linkage().","message":"Input to linkage() expects a 2D array of observations (n_samples, n_features) or a condensed distance matrix. If you pass a square distance matrix, fastcluster will interpret it as observations, leading to silent incorrect results.","severity":"gotcha","affected_versions":"all"},{"fix":"Use scipy.cluster.hierarchy.linkage with method='centroid' or 'median' if you need exact scipy compatibility.","message":"The 'fastcluster.linkage' function with 'method'='centroid' or 'median' returns results that differ from scipy.cluster.hierarchy in terms of how the distance matrix is updated. These methods are considered deprecated in favor of scipy's implementations.","severity":"deprecated","affected_versions":">=1.2.0"},{"fix":"If you must use precomputed distances with Ward linkage, use scipy.cluster.hierarchy.linkage with method='ward' after ensuring distances are Euclidean squared.","message":"fastcluster does not support precomputed distance matrices with the 'ward' method — it always recomputes Euclidean distances internally. This can cause unexpected memory usage or errors if you pass a distance matrix expecting Ward's method.","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":"Run 'pip install fastcluster' to install the package.","cause":"Package not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'fastcluster'"},{"fix":"Convert square matrix to condensed form: from scipy.spatial.distance import squareform; condensed = squareform(square_matrix).","cause":"Input to linkage() is a square distance matrix, not a condensed one.","error":"ValueError: The condensed distance matrix must be of length (n*(n-1)//2) for n points, but got ..."},{"fix":"Ensure input array is contiguous and dtype is float64. Try X = np.ascontiguousarray(X, dtype=np.float64).","cause":"Sometimes occurs when using method='centroid' or 'median' with certain data types or versions of numpy.","error":"TypeError: 'numpy.float64' object cannot be interpreted as an integer"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}