Numpy数组array和矩阵matrix转换方法
2019-08-05 14:17
1556 查看
1、ndarray转换成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))
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- Numpy中矩阵matrix读取一列的方法及数组和矩阵的相互转换实例
- Numpy中矩阵matrix读取一列的方法及数组和矩阵的相互转换
- Python Numpy的数组array和矩阵matrix
- Python Numpy的数组array和矩阵matrix
- Python Numpy的数组array和矩阵matrix的用法与区别
- Python Numpy的数组array和矩阵matrix
- Numpy中数组array和矩阵matrix区别
- numpy中数组和矩阵的索引方法及不同点
- PHP实现数组array转换成xml的方法
- Array.prototype.slice.call()详解及转换数组的方法
- Numpy 将二维图像矩阵转换为一维向量的方法
- javescript日期设置/大小写转换/charAt/indexOf/split【slice】/substr/math/Array数组方法
- leetcode -- 566. Reshape the Matrix 【矩阵转换 + 不同数组下标映射】
- Python3 列表,数组,矩阵的相互转换的方法示例
- PHP实现数组array转换成xml的方法
- 【笔记】js Array.prototype.slice.call(arguments) 将函数的参数转换为数组方法的见解
- Python numpy库中的array,list与矩阵的乘法,以及增添元素的方法
- Python之数组(array)使用方法总结与Numpy中的数组用法
- leetCode 108.Convert Sorted Array to Binary Search Tree(将排序数组转换为BST) 解题思路和方法
- Array.prototype.slice.call()详解及转换数组的方法