
- 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 - fiedler() Function
The scipy.linalg.fiedler() method gives a Fiedler matrix, which is a symmetric matrix with each element being the absolute difference between two items of an input vector. F[i,j] is mathematically defined as a[i]a[j], where a is the input vector. The method is simple and effective for the construction of structured matrices that can be used in various computing applications.
Fiedler matrices are used frequently in graph theory, numerical analysis, and optimization problems. It is also used to generate Laplacian matrices and solve symmetric or distance-based relationship problems.
If the input is not one-dimensional, then errors might occur because the procedure requires a one-dimensional array or sequence. An empty input will produce an empty matrix that may cause trouble in subsequent computations. Moreover, big input sizes may increase memory utilization and computation time.
Syntax
The syntax for the SciPy fiedler() method is as follows −
.fiedler(a)
Parameters
This method accepts the following parameters −
a (array-like) − A 1D input array or sequence from which the Fiedler matrix is constructed.
Return Value
F (ndarray) − A symmetric matrix of shape (len(a), len(a)), where each element is computed as a[i]a[j]
Example 1
This example shows how to create a symmetric Fiedler matrix with the fiedler() function from scipy.linalg. The function accepts the input array [1, 3, 5] and computes a matrix, with each entry representing the absolute difference between pairs of entries from the array.
For example, the element in the first row and second column is 13=2. The diagonal elements are zero (xx=0), and the matrix obtained is symmetric because the absolute difference does not depend on the order of the entries.
import numpy as np from scipy.linalg import fiedler # Input array a = [1, 3, 5] # Generate the Fiedler matrix matrix = fiedler(a) print(matrix)
When we run above program, it produces following result
[[0 2 4] [2 0 2] [4 2 0]]
Example 2
The Fiedler matrix, which is generated from the absolute differences between members of the input array using fiedler() method, always produces symmetric matrices with non-negative values.
This example illustrates how the Fiedler matrix works on an input array with negative values like [-2 0 4]. The matrix is then calculated as the absolute differences of all pairs of elements in the array. Each entry in the matrix is the size of a difference between two elements.
from scipy.linalg import fiedler # Input array with negative numbers a = [-2, 0, 4] # Generate the Fiedler matrix matrix = fiedler(a) print(matrix)
Output of the above code is as follows
[[0 2 6] [2 0 4] [6 4 0]]
Example 3
This example demonstrates how the Fiedler matrix, created from the input array [10, 20, 30, 40], may be utilized to do advanced numerical operations such as analyzing spectral qualities using its eigenvalues by eigvals() method. These eigenvalues disclose vital information about the matrix's structure and behavior.
The computed eigenvalues are [40,10,10,40], indicating that the Fiedler matrix's spectrum is symmetrical.
import numpy as np from scipy.linalg import fiedler, eigvals # Input array a = [10, 20, 30, 40] # Generate the Fiedler matrix matrix = fiedler(a) # Compute eigenvalues eigenvalues = eigvals(matrix) print("Fiedler Matrix:") print(matrix) print("\nEigenvalues:") print(eigenvalues)
Output of the above code is as follows
Fiedler Matrix: [[ 0 10 20 30] [10 0 10 20] [20 10 0 10] [30 20 10 0]] Eigenvalues: [ 51.6227766 +0.j -34.14213562+0.j -11.6227766 +0.j -5.85786438+0.j]
Example 4
Let us imagine a social scientist analyzing relationships among a group of people, with the input array [1, 2, 3, 4, 5] representing age. To calculate the absolute differences between these properties, use the fiedler() method from scipy.linalg.
The differences are then encoded in a heatmap, with smaller differences (darker cells) indicating similarity and greater differences (lighter cells) highlighting discrepancies.
import numpy as np import matplotlib.pyplot as plt from scipy.linalg import fiedler # Input array a = [1, 2, 3, 4, 5] # Generate the Fiedler matrix matrix = fiedler(a) # Visualize the Fiedler matrix plt.imshow(matrix, cmap='viridis', interpolation='nearest') plt.colorbar() plt.title("Fiedler Matrix Heatmap") plt.show()