Numpy数组array和矩阵matrix转换方法

作者:rosefun96 时间:2021-06-25 06:17:26 

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))

来源:https://blog.csdn.net/rosefun96/article/details/79059549

标签:Numpy,array,matrix,转换
0
投稿

猜你喜欢

  • 详解numpy矩阵的创建与数据类型

    2022-07-12 15:59:17
  • sqlserver 触发器学习(实现自动编号)

    2012-10-07 10:58:03
  • Python爬虫之获取心知天气API实时天气数据并弹窗提醒

    2023-04-17 14:40:58
  • Python Tkinter Menu组件详解

    2021-07-24 06:51:18
  • Python机器学习入门(三)之Python数据准备

    2021-05-27 19:49:42
  • python工具——Mimesis的简单使用教程

    2021-08-06 07:27:23
  • Python高级编程之继承问题详解(super与mro)

    2023-08-08 18:58:47
  • C#调用Python程序传参数获得返回值

    2023-10-11 06:49:52
  • PHP echo,print,printf,sprintf函数之间的区别与用法详解

    2023-11-21 14:12:25
  • python密码学简单替代密码解密及测试教程

    2023-09-30 08:13:00
  • Python中turtle库的使用实例

    2023-08-01 23:05:56
  • Python NumPy中的随机数及ufuncs函数使用示例详解

    2021-09-22 15:29:08
  • django admin 添加自定义链接方式

    2022-09-22 05:33:14
  • jupyter notebook清除输出方式

    2021-05-08 02:51:13
  • Python中可以用三种方法判断文件是否存在

    2022-05-11 10:15:41
  • PLSQL导入dmp文件的详细完整步骤

    2023-06-26 11:45:32
  • 浅析PHP中的字符串编码转换(自动识别原编码)

    2023-09-08 08:04:44
  • Python如何对文件进行重命名

    2022-01-20 12:31:51
  • Python3使用 GitLab API 进行批量合并分支

    2023-05-26 08:38:53
  • python实现图片处理和特征提取详解

    2023-10-04 02:28:16
  • asp之家 网络编程 m.aspxhome.com