2019-08-05 16:16:23 3890瀏覽
今天千鋒扣丁學堂Python培訓老師給大家分享一篇關于Numpy數(shù)組array和矩陣matrix轉換方法,文中通過示例代碼介紹的非常詳細,下面我們一起來看一下吧。
import numpy as np from numpy import random,mat r_arr=random.rand(4,4) print('r_arr',r_arr) r_mat=mat(r_arr) print(r_mat.I)#求逆
r_arr [[ 0.65603592 0.39908438 0.44722351 0.92652759] [ 0.32357477 0.45384697 0.31687359 0.73861219] [ 0.3534119 0.12693696 0.15701767 0.9163409 ] [ 0.36515841 0.87377377 0.44150506 0.4605718 ]] r_mat [[ 0.65603592 0.39908438 0.44722351 0.92652759] [ 0.32357477 0.45384697 0.31687359 0.73861219] [ 0.3534119 0.12693696 0.15701767 0.9163409 ] [ 0.36515841 0.87377377 0.44150506 0.4605718 ]] [[ 2.20907786 -11.21482242 4.73076477 4.12886716] [ -1.79239654 -4.48728612 3.52875987 3.78121743] [ 2.86148809 15.82430961 -11.71577803 -7.82425058] [ -1.09402215 2.23536661 0.78545617 -0.77549894]]
import numpy as np from numpy import random,mat,eye r_arr=random.rand(4,4) print('r_arr',r_arr) r_mat=mat(r_arr) print('r_mat',r_mat) r_invmat=r_mat.I # print(r_mat.I) r2_mat=r_mat*r_invmat print('r2_mat',r2_mat) print('error',r2_mat-eye(4))
【關注微信公眾號獲取更多學習資料】 【掃碼進入Python全棧開發(fā)免費公開課】