知行编程网知行编程网  2022-09-06 14:30 知行编程网 隐藏边栏  276 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python中如何基于numpy创建矩阵的相关知识,包括Python矩阵,以及python求矩阵的逆这些编程知识,希望对大家有参考作用。


如何在python中基于numpy创建矩阵


python的功能强大依赖于各种库发挥的作用,例如

numpy库就提供了矩阵运算的功能,如果我们想要进行矩阵运算,首先要导入

numpy的包,创建矩阵。本文介绍

python中基于numpy创建矩阵的三种方法:

1、手动创建;

2、利用


numpy数组创建;

3、


使用numpy.matix()函数创建矩阵。








一、导入

numpy


>>>from numpy import *;#导入numpy的库函数
>>>import numpy as np; #这个方式使用numpy的函数时,需要以np.开头。



二、


python基于numpy创建矩阵方法




1、手动创建

a=np.mat('1 2 3;4 5 6;7 8 9') # 中间打逗号也可以 b=np.mat('1,2,3;4,5,6;7,8,9')



2、利用


numpy数组创建

c=np.mat(np.arange(9)) #一维的矩阵
c=np.mat(np.arange(9).reshape(3,3))



3、


使用numpy.matix()函数创建矩阵

import numpy as np
 
# create 2x2 matrix
a = np.matrix([[1, 2], [3, 4]])  # using array of array
print('2x2 matrix is:\n', a)
# using shape attribute to get the tuple describing matrix shape
print('The dimension of the matrix is :', a.shape)


以上就是python中基于numpy创建矩阵的三种方法,希望对你创建矩阵有所帮助~

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享