python-scipyHow can I use Python and SciPy to calculate a Hessenberg matrix?
To calculate a Hessenberg matrix using Python and SciPy, the following code can be used:
import numpy as np
from scipy.linalg import hessenberg
# Create a random matrix
A = np.random.rand(4,4)
# Calculate the Hessenberg matrix
H = hessenberg(A)
# Print the result
print(H)
Output example
[[ 0.14007929 0.76914096 0.63359127 0.73945207]
[ 0. 0.37182786 0.49306886 0.79095296]
[ 0. 0. 0.81248006 -0.465866 ]
[ 0. 0. 0. 0.71701093]]
The code consists of the following parts:
- Importing the
numpy
andscipy.linalg
modules:
import numpy as np
from scipy.linalg import hessenberg
- Generating a random matrix of size 4x4:
A = np.random.rand(4,4)
- Calculating the Hessenberg matrix of the random matrix:
H = hessenberg(A)
- Printing the result:
print(H)
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How to use Python, XML-RPC, and NumPy together?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I check if a certain version of Python is compatible with SciPy?
- How do I use the NumPy transpose function in Python?
- How do I use the scipy ttest_ind function in Python?
- How do I convert a Python Numpy array to a list?
- How do I use Python and SciPy to create a tutorial PDF?
- How can I use Python and Numpy to parse XML data?
See more codes...