在 Python/NumPy 中计算矩阵的 Jordan 标准形式 [英] Compute Jordan normal form of matrix in Python / NumPy

查看:67
本文介绍了在 Python/NumPy 中计算矩阵的 Jordan 标准形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MATLAB 中,您可以使用函数 jordan 计算矩阵的 Jordan 范式.

In MATLAB you can compute the Jordan normal form of a matrix by using the the function jordan.

NumPy 和 SciPy 中是否有等效的函数?

It there an equivalent function available in NumPy and SciPy?

推荐答案

MATLAB jordan 函数是来自 Symbolic Math Toolbox,因此从 SymPy 库中获取 Python 替代品似乎并非不合理.具体来说,Matrix 类具有方法 jordan_form.创建 sympy Matrix 时,可以将 numpy 数组作为参数传递.例如,以下内容来自维基百科关于乔丹范式的文章:

The MATLAB jordan function is from the Symbolic Math Toolbox, so it does not seem unreasonable to get its Python replacement from the SymPy library. Specifically, the Matrix class has the method jordan_form. You can pass a numpy array as an argument when you create a sympy Matrix. For example, the following is from the wikipedia article on the Jordan normal form:

In [1]: import numpy as np

In [2]: from sympy import Matrix

In [3]: a = np.array([[5, 4, 2, 1], [0, 1, -1, -1], [-1, -1, 3, 0], [1, 1, -1, 2]])

In [4]: m = Matrix(a)

In [5]: m
Out[5]: 
Matrix([
[ 5,  4,  2,  1],
[ 0,  1, -1, -1],
[-1, -1,  3,  0],
[ 1,  1, -1,  2]])

In [6]: P, J = m.jordan_form()

In [7]: J
Out[7]: 
Matrix([
[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 4, 1],
[0, 0, 0, 4]])

这篇关于在 Python/NumPy 中计算矩阵的 Jordan 标准形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆