python怎么定义空矩阵_Python(NumPy,SciPy),找到矩阵的空空间

1586010002-jmsa.png

I'm trying to find the null space (solution space of Ax=0) of a given matrix. I've found two examples, but I can't seem to get either to work. Moreover, I can't understand what they're doing to get there, so I can't debug. I'm hoping someone might be able to walk me through this.

The documentation pages (numpy.linalg.svd, and numpy.compress) are opaque to me. I learned to do this by creating the matrix C = [A|0], finding the reduced row echelon form and solving for variables by row. I can't seem to follow how it's being done in these examples.

Thanks for any and all help!

Here is my sample matrix, which is the same as the wikipedia example:

A = matrix([

[2,3,5],

[-4,2,3]

])

Method (found here, and here):

import scipy

from scipy import linalg, matrix

def null(A, eps=1e-15):

u, s, vh = scipy.linalg.svd(A)

null_mask = (s <= eps)

null_space = scipy.compress(null_mask, vh, axis=0)

return scipy.transpose(null_space)

When I try it, I get back an empty matrix:

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)

[GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import scipy

>>> from scipy import linalg, matrix

>>> def null(A, eps=1e-15):

... u, s, vh = scipy.linalg.svd(A)

... null_mask = (s <= eps)

... null_space = scipy.compress(null_mask, vh, axis=0)

... return scipy.transpose(null_space)

...

>>> A = matrix([

... [2,3,5],

... [-4,2,3]

... ])

>>>

>>> null(A)

array([], shape=(3, 0), dtype=float64)

>>>

解决方案

It appears to be working okay for me:

A = matrix([[2,3,5],[-4,2,3],[0,0,0]])

A * null(A)

>>> [[ 4.02455846e-16]

>>> [ 1.94289029e-16]

>>> [ 0.00000000e+00]]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值