在Python/NumPy中计算约旦范式的矩阵 [英] Compute Jordan normal form of matrix in Python / NumPy

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

问题描述

在MATLAB中,您可以使用函数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矩阵时,可以将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中计算约旦范式的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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