
- 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 - tanhm() Function
The scipy.linalg.tanhm() method calculates the hyperbolic tangent of a square matrix A. The matrix hyperbolic tangent is given by sinh(A)cosh^1(A) where sinh and cosh represent the matrix's hyperbolic sine and cosine, respectively. This is based on the decomposition of the matrices and then applies the hyperbolic tangent to each of the elements in the matrix.
The physicists and engineers mostly make use of this method in solving differential equations, checking stability, and describing hyperbolic events. Results turn out useful in dynamic systems that exhibit hyperbolic behavior over time.
Errors may occur when input matrix A isn't square: hyperbolic tangent functions can be defined for square matrices. Furthermore, matrices with complex eigenvalues can produce computational mistakes or undefined outcomes, making input validation critical.
The method can be combined with expm() (matrix exponential) or logm() (matrix logarithm) for dynamic simulations and stability studies, where hyperbolic transformations are required.
Syntax
The syntax for the SciPy tanhm() method is as follows −
.tanhm(A)
Parameters
This method accepts the following parameters −
A (N, N) array_like − Input square matrix (nn), real or complex.
Return Value
The hyperbolic tangent of the matrix 'A', of the same shape as 'A'.
Example 1
The below code, is the basic example of tanhm() method where we have created a 2x2 matrix to compute the hyperbolic tangent and the result will also be in the same shape of the input matrix.
import numpy as np import scipy.linalg from scipy.linalg import tanhm A = np.array([[1, 2], [3, 4]]) # Compute the hyperbolic tangent of the matrix tanh_matrix = scipy.linalg.tanhm(A) print("Matrix Hyperbolic Tangent:\n", tanh_matrix)
When we run above program, it produces following result
Matrix Hyperbolic Tangent: [[-0.03207326 0.47207856] [ 0.70811784 0.67604458]]
Example 2
For symmetric matrices, the tanhm() method retains the symmetry in the output.
In the below code we have created a symmetric 22 matrix as input into the tanhm() method. The function computes the hyperbolic tangent while preserving the symmetric structure in the result.
import numpy as np import scipy.linalg from scipy.linalg import tanhm # Symmetric matrix A = np.array([[1, 2], [2, 1]]) tanh_matrix = tanhm(A) print("Matrix Hyperbolic Tangent:\n", tanh_matrix)
Following is an output of the above code
Matrix Hyperbolic Tangent: [[0.1167303 0.87832445] [0.87832445 0.1167303 ]]
Example 3
Combining tanhm() and expm() simulates dynamic systems with hyperbolic and exponential transformations.
The 22 matrix A is transformed using tanhm() and then passed to expm() to compute its exponential. The output exhibits the interaction of hyperbolic and exponential dynamics.
import numpy as np from scipy.linalg import expm, inv # Input matrix A = np.array([[1, 2], [3, 4]]) # Compute sinh(A) and cosh(A) sinh_A = (expm(A) - expm(-A)) / 2 cosh_A = (expm(A) + expm(-A)) / 2 # Compute tanh(A) tanh_matrix = sinh_A @ inv(cosh_A) # Compute the exponential of the hyperbolic tangent matrix expm_matrix = expm(tanh_matrix) print("Exponential of Hyperbolic Tangent Matrix:\n", expm_matrix)
Output of the above code is as follows
Exponential of Hyperbolic Tangent Matrix: [[1.18247368 0.70246666] [1.05369999 2.23617367]]