<分区>
必须有一种简单的方法来获得一个小的零空间(比如 3x3) python 的 numpy 或 scipy 中的矩阵。
MATLAB 可以在这方面做得很好。比方说:
A = [1 2 3;
2 3 4;
2 4 6]
rank(A) % rank is 2
null(A, 'r') % ask matlab to be ('r') reasonable about
% its choice of a vector in A's nullspace
最后一条命令的输出是:
1
-2
1
它出现了——这是真的吗? - 在 numpy 中事情并不那么简单:
import numpy as np
A = array(([1, 2, 3], [2, 3, 4], [2, 4, 6]))
np.linalg.matrix_rank(A) # ok, getting the rank of a matrix is this esay, even if
# it takes more keystrokes, but how about its null space
从我目前搜索的内容来看,似乎需要调用
svd
分解函数首先得到零空间。
在 python 中必须有更简单的方法来执行此操作。
此外,在 matlab 中可以说:
format rat
避免在输出中出现长小数部分
矩阵。 (例如,当格式设置为 'rational' 时,输出矩阵中的条目将看起来像 1/2
而不是看起来更丑的 0.5000000
)
python有没有类似的特性,或者说使用python的人注定要失败吗? 永远看着这些小数?
提前致谢。
d.