python np matrix_[PYTHON] NumPy Matrix的学习

from numpy import *

class numpyMatrix:

if __name__ == '__main__':

vArray = random.rand(4, 4)

print('This is a array sample \n', vArray)

vMatrix = mat(vArray)

print('This is a matrix sample \n', vMatrix)

vInverseMatrix = vMatrix.I

print('This is a inverse matrix sample \n', vInverseMatrix)

vEye = vMatrix * vInverseMatrix

print('This is a eye matrix sample \n', vEye)

vEye = eye(4)

print('This is a eye matrix sample :\n', vEye)

运行结果:

This is a array sample

[[0.24317484 0.61940417 0.33355164 0.21432283]

[0.94727173 0.52829176 0.93154304 0.62385301]

[0.23583112 0.38438448 0.24753542 0.33686847]

[0.39015535 0.20420862 0.60581605 0.40163816]]

This is a matrix sample

[[0.24317484 0.61940417 0.33355164 0.21432283]

[0.94727173 0.52829176 0.93154304 0.62385301]

[0.23583112 0.38438448 0.24753542 0.33686847]

[0.39015535 0.20420862 0.60581605 0.40163816]]

This is a inverse matrix sample

[[-1.17966778 3.00957773 -0.15569821 -3.91460452]

[ 1.99872468 -0.18199604 0.08541396 -0.85551338]

[ 2.04836455 -1.20451955 -3.7130608 3.89217241]

[-2.9599658 -1.01414768 5.70846163 0.8566581 ]]

This is a eye matrix sample

[[ 1.00000000e+00 -8.73454384e-17 1.00540377e-18 1.70506004e-16]

[-1.66719838e-18 1.00000000e+00 -2.35196232e-16 4.96751138e-16]

[ 6.75476473e-18 4.68068042e-17 1.00000000e+00 1.35672040e-16]

[-6.83787177e-17 -6.67233694e-17 -7.59014515e-17 1.00000000e+00]]

This is a eye matrix sample :

[[1. 0. 0. 0.]

[0. 1. 0. 0.]

[0. 0. 1. 0.]

[0. 0. 0. 1.]]

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值