[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.]]

你可能感兴趣的:([PYTHON] NumPy Matrix的学习)