
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - single() Method
The SciPy single() method performs the task of single/minimimum/nearest linkage on a condensed matrix. The usage of this method is to define the distance between two clusters like a shortest distance between two different points.
In the field of data science, we use this method for cluster Analysis. It is used to identify the data pattern recognition, grouping items, and anomaly detection.
Syntax
Following is the syntax of the SciPy single() method −
single(y)
Parameters
This function accepts only a single parameters −
- y: This variable is accepted as a parameter in the method single() that stores the list array integers for data plotting.
Return value
This method returns the linkage matrix(result).
Example 1
Following is the SciPy single() method illustrate the task of single linkage by plotting the data points.
import numpy as np from scipy.cluster.hierarchy import single, dendrogram import matplotlib.pyplot as plt # Distance matrix y = np.array([0.5, 0.2, 0.3, 0.4, 0.8, 0.6]) # single linkage clustering result = single(y) # Plot the dendrogram plt.figure(figsize=(6, 4)) dendrogram(result) plt.title('Dendrogram - Single Linkage') plt.xlabel('indexes') plt.ylabel('Distance') plt.show()
Output
The above code produces the following result −

Example 2
Below the example demonstrate the task of single linkage clustering on random data.
import numpy as np from scipy.spatial.distance import pdist from scipy.cluster.hierarchy import single, dendrogram import matplotlib.pyplot as plt # Generate random data data = np.random.rand(5, 2) # calculate the distance matrix y = pdist(data, metric='euclidean') # single linkage clustering result = single(y) # Plot the dendrogram plt.figure(figsize=(6, 4)) dendrogram(result) plt.title('Dendrogram - Single Linkage on Random Data') plt.xlabel('indexes') plt.ylabel('Distance') plt.show()
Output
The above code produces the following result −

Example 3
In this example, we use the metric type as cityblock to calculate the distance matrix from a given dataset and utilize the single linkage clustering. Then we use the method dendogram() which is helpful for plotting and visualizing the clustering.
import numpy as np from scipy.spatial.distance import pdist from scipy.cluster.hierarchy import single, dendrogram import matplotlib.pyplot as plt # Given data data = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) # calculate the distance matrix using a custom metric y = pdist(data, metric='cityblock') # single linkage clustering result = single(y) # Plot the dendrogram plt.figure(figsize=(6, 4)) dendrogram(result) plt.title('Dendrogram - Single Linkage with Cityblock Distance') plt.xlabel('indexes') plt.ylabel('Distance') plt.show()
Output
The above code produces the following result −
