当前位置: 首页 > news >正文

新疆建设厅官方网站资质公告营销平台有哪些

新疆建设厅官方网站资质公告,营销平台有哪些,青田网页设计公司,色弱做网站文章目录矩阵生成与常用操作矩阵生成矩阵转置查看矩阵特性矩阵乘法计算相关系数矩阵计算方差、协方差、标准差计算特征值与特征向量计算逆矩阵求解线性方程组奇异值分解函数向量化矩阵生成与常用操作 矩阵生成 扩展库numpy中提供的matrix()函数可以用来把列表、元组、range对…

文章目录

  • 矩阵生成与常用操作
    • 矩阵生成
    • 矩阵转置
    • 查看矩阵特性
    • 矩阵乘法
    • 计算相关系数矩阵
    • 计算方差、协方差、标准差
  • 计算特征值与特征向量
  • 计算逆矩阵
  • 求解线性方程组
  • 奇异值分解
  • 函数向量化

矩阵生成与常用操作

矩阵生成

扩展库numpy中提供的matrix()函数可以用来把列表、元组、range对象等Python可迭代对象转换为矩阵。

>>> import numpy as np
>>> x=np.matrix([[1,2,3],[4,5,6]])
>>> y=np.matrix([1,2,3,4,5,6])
>>> # 对矩阵x来说,x[1,1]和x[1][1]的含义不一样
>>> x
matrix([[1, 2, 3],[4, 5, 6]])
>>> y
matrix([[1, 2, 3, 4, 5, 6]])
>>> x[1,1]
5

矩阵转置

>>> x.T
matrix([[1, 4],[2, 5],[3, 6]])
>>> y.T
matrix([[1],[2],[3],[4],[5],[6]])

查看矩阵特性

>>> x=np.matrix([[1,2,3],[4,5,6]])
>>> x.mean() # 所有元素平均值
3.5
>>> x.mean(axis=0) # 纵向平均值
matrix([[2.5, 3.5, 4.5]])
>>> x.mean(axis=1) # 横向平均值
matrix([[2.],[5.]])
>>> x.sum() # 所有元素之和
21
>>> x.max(axis=1) # 横向最大值
matrix([[3],[6]])
>>> x.argmax(axis=1) # 横向最大值下标
matrix([[2],[2]], dtype=int64)
>>> x.diagonal() # 对角线元素
matrix([[1, 5]])
>>> x.nonzero() # 非0元素下标
(array([0, 0, 0, 1, 1, 1], dtype=int64), array([0, 1, 2, 0, 1, 2], dtype=int64))
>>> # 行下标列表和列下标列表

矩阵乘法

一个mxp的矩阵和一个pxn的矩阵,它们的乘积为一个mxn的矩阵

>>> x=np.matrix([[1,2,3],[4,5,6]])
>>> y=np.matrix([[1,2],[3,4],[5,6]])
>>> x*y
matrix([[22, 28],[49, 64]])

计算相关系数矩阵

>>> np.corrcoef([1,2,3,4],[4,3,2,1]) # 负相关,变化反向相反
array([[ 1., -1.],[-1.,  1.]])
>>> np.corrcoef([1,2,3,4],[8,3,2,1]) # 负相关,变化反向相反
array([[ 1.        , -0.91350028],[-0.91350028,  1.        ]])
>>> np.corrcoef([1,2,3,4],[1,2,3,4]) # 正相关,变化反向一致
array([[1., 1.],[1., 1.]])
>>> np.corrcoef([1,2,3,4],[1,2,3,40]) # 正相关,变化趋势接近
array([[1.       , 0.8010362],[0.8010362, 1.       ]])

计算方差、协方差、标准差

>>> np.cov([1,1,1,1,1]) # 方差
array(0.)
>>> np.std([1,1,1,1,1]) # 标准差
0.0
>>> x=[-2.1,-1,4.3]
>>> y=[3,1.1,0.12]
>>> X=np.vstack((x,y))
>>> X
array([[-2.1 , -1.  ,  4.3 ],[ 3.  ,  1.1 ,  0.12]])
>>> np.cov(X) # 协方差
array([[11.71      , -4.286     ],[-4.286     ,  2.14413333]])
>>> np.cov(x,y)
array([[11.71      , -4.286     ],[-4.286     ,  2.14413333]])
>>> np.std(X) # 标准差
2.2071223094538484
>>> np.std(X,axis=1)
array([2.79404128, 1.19558447])
>>> np.cov(x) # 方差
array(11.71)

计算特征值与特征向量

>>> A=np.array([[1,-3,3],[3,-5,3],[6,-6,4]])
>>> e,v=np.linalg.eig(A) # 特征值与特征向量
>>> e
array([ 4.+0.00000000e+00j, -2.+1.10465796e-15j, -2.-1.10465796e-15j])
>>> v
array([[-0.40824829+0.j        ,  0.24400118-0.40702229j,0.24400118+0.40702229j],[-0.40824829+0.j        , -0.41621909-0.40702229j,-0.41621909+0.40702229j],[-0.81649658+0.j        , -0.66022027+0.j        ,-0.66022027-0.j        ]])
>>> np.dot(A,v) # 矩阵与特征向量的乘积
array([[-1.63299316+0.00000000e+00j, -0.48800237+8.14044580e-01j,-0.48800237-8.14044580e-01j],[-1.63299316+0.00000000e+00j,  0.83243817+8.14044580e-01j,0.83243817-8.14044580e-01j],[-3.26598632+0.00000000e+00j,  1.32044054-5.55111512e-16j,1.32044054+5.55111512e-16j]])
>>> e*v # 特征值与特征向量的乘积
array([[-1.63299316+0.00000000e+00j, -0.48800237+8.14044580e-01j,-0.48800237-8.14044580e-01j],[-1.63299316+0.00000000e+00j,  0.83243817+8.14044580e-01j,0.83243817-8.14044580e-01j],[-3.26598632+0.00000000e+00j,  1.32044054-7.29317578e-16j,1.32044054+7.29317578e-16j]])
>>> np.isclose(np.dot(A,v),e*v) # 验证两者是否相等
array([[ True,  True,  True],[ True,  True,  True],[ True,  True,  True]])

计算逆矩阵

>>> x=np.matrix([[1,2,3],[4,5,6],[7,8,0]])
>>> y=np.linalg.inv(x) # 计算逆矩阵
>>> y
matrix([[-1.77777778,  0.88888889, -0.11111111],[ 1.55555556, -0.77777778,  0.22222222],[-0.11111111,  0.22222222, -0.11111111]])
>>> x*y # 对角线元素为1,其他元素为0或近似为0
matrix([[ 1.00000000e+00,  5.55111512e-17,  1.38777878e-17],[ 5.55111512e-17,  1.00000000e+00,  2.77555756e-17],[ 1.77635684e-15, -8.88178420e-16,  1.00000000e+00]])
>>> y*x
matrix([[ 1.00000000e+00, -1.11022302e-16,  0.00000000e+00],[ 8.32667268e-17,  1.00000000e+00,  2.22044605e-16],[ 6.93889390e-17,  0.00000000e+00,  1.00000000e+00]])

求解线性方程组

{a11x1+a12x2+...+a1nxn=b1a21x1+a22x2+...+a2nxn=b2...an1x1+an2x2+...+annxn=bn\begin{cases} a11x1+a12x2+...+a1nxn=b1\\ a21x1+a22x2+...+a2nxn=b2\\ ...\\ an1x1+an2x2+...+annxn=bn\\ \end{cases}a11x1+a12x2+...+a1nxn=b1a21x1+a22x2+...+a2nxn=b2...an1x1+an2x2+...+annxn=bn
可以写作矩阵相乘的形式 ax=b
其中,a为nxn的矩阵,x和b为nx1的矩阵

>>> a=np.array([[3,1],[1,2]]) # 系数矩阵
>>> b=np.array([9,8]) # 系数矩阵
>>> x=np.linalg.solve(a,b) # 求解
>>> x
array([2., 3.])
>>> np.dot(a,x) # 验证
array([9., 8.])
>>> np.linalg.lstsq(a,b) # 最小二乘解,返回解、余项、a的秩、a的奇异值Warning (from warnings module):File "<pyshell#77>", line 1
FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
(array([2., 3.]), array([], dtype=float64), 2, array([3.61803399, 1.38196601]))
>>>

有报错不要慌

>>> np.linalg.lstsq(a,b,rcond=None) # 最小二乘解,返回解、余项、a的秩、a的奇异值
(array([2., 3.]), array([], dtype=float64), 2, array([3.61803399, 1.38196601]))

可以写个方程去尝试一下,我试了一下,应该是没有问题的。

奇异值分解

把矩阵a分解为u*np.diag(s)*v的形式并返回u、s和v。其中数组s中的元素是矩阵a的元素值

>>> import numpy as np
>>> a=np.matrix([[1,2,3],[4,5,6],[7,8,9]])
>>> u,s,v=np.linalg.svd(a) # 奇异值分解
>>> u
matrix([[-0.21483724,  0.88723069,  0.40824829],[-0.52058739,  0.24964395, -0.81649658],[-0.82633754, -0.38794278,  0.40824829]])
>>> s
array([1.68481034e+01, 1.06836951e+00, 4.41842475e-16])
>>> v
matrix([[-0.47967118, -0.57236779, -0.66506441],[-0.77669099, -0.07568647,  0.62531805],[-0.40824829,  0.81649658, -0.40824829]])
>>> u*np.diag(s)*v # 验证
matrix([[1., 2., 3.],[4., 5., 6.],[7., 8., 9.]])

函数向量化

>>> mat=np.matrix([[1,2,3],[4,5,6]])
>>> mat
matrix([[1, 2, 3],[4, 5, 6]])
>>> import math
>>> vecFactorial=np.vectorize(math.factorial) # 函数向量化
>>> vecFactorial(mat)
matrix([[  1,   2,   6],[ 24, 120, 720]])

文章转载自:
http://dinncometallurgic.stkw.cn
http://dinncoplutocratical.stkw.cn
http://dinncoezra.stkw.cn
http://dinncooctan.stkw.cn
http://dinncoknapweed.stkw.cn
http://dinncoturnstone.stkw.cn
http://dinncostopper.stkw.cn
http://dinncoseignorial.stkw.cn
http://dinncocystolith.stkw.cn
http://dinncodirectorial.stkw.cn
http://dinncoheronsbill.stkw.cn
http://dinncokrooboy.stkw.cn
http://dinncocalk.stkw.cn
http://dinncoexhaustee.stkw.cn
http://dinncocmd.stkw.cn
http://dinncosubdivision.stkw.cn
http://dinncosuccessful.stkw.cn
http://dinncoaerobee.stkw.cn
http://dinncootranto.stkw.cn
http://dinncodisinclined.stkw.cn
http://dinncoclonicity.stkw.cn
http://dinncoembassy.stkw.cn
http://dinncoewery.stkw.cn
http://dinncocheekily.stkw.cn
http://dinncoogee.stkw.cn
http://dinncocytovirin.stkw.cn
http://dinncoimpressionist.stkw.cn
http://dinncolanguistics.stkw.cn
http://dinncocarbamidine.stkw.cn
http://dinncobuster.stkw.cn
http://dinncostriped.stkw.cn
http://dinncospectatoritis.stkw.cn
http://dinncomelee.stkw.cn
http://dinncomesomorph.stkw.cn
http://dinncotabernacular.stkw.cn
http://dinncoacquirement.stkw.cn
http://dinncoadmittedly.stkw.cn
http://dinncocursorily.stkw.cn
http://dinncocantrip.stkw.cn
http://dinncovirgilian.stkw.cn
http://dinncostepdance.stkw.cn
http://dinncoconfirmatory.stkw.cn
http://dinncobufalin.stkw.cn
http://dinncodeaden.stkw.cn
http://dinncocreosol.stkw.cn
http://dinncolaconia.stkw.cn
http://dinncosag.stkw.cn
http://dinncoposadero.stkw.cn
http://dinncobeardless.stkw.cn
http://dinncoservings.stkw.cn
http://dinnconondefense.stkw.cn
http://dinncopleiades.stkw.cn
http://dinncomanifer.stkw.cn
http://dinncopersecute.stkw.cn
http://dinncoheadwaters.stkw.cn
http://dinncoactress.stkw.cn
http://dinncoindigotic.stkw.cn
http://dinncojuvenescent.stkw.cn
http://dinncooversweet.stkw.cn
http://dinncoanneal.stkw.cn
http://dinncoantehuman.stkw.cn
http://dinncounloveliness.stkw.cn
http://dinncopigout.stkw.cn
http://dinncomicromechanism.stkw.cn
http://dinncoallied.stkw.cn
http://dinncohexahedral.stkw.cn
http://dinncofungoid.stkw.cn
http://dinncogoniometer.stkw.cn
http://dinncobeforetime.stkw.cn
http://dinncobenzonitrile.stkw.cn
http://dinncolusterless.stkw.cn
http://dinncosubequal.stkw.cn
http://dinncosweep.stkw.cn
http://dinncosaltless.stkw.cn
http://dinncoinlayer.stkw.cn
http://dinncoracerunner.stkw.cn
http://dinncobeggar.stkw.cn
http://dinncoabsinthe.stkw.cn
http://dinncoautocoid.stkw.cn
http://dinncoscramasax.stkw.cn
http://dinncoflorescence.stkw.cn
http://dinncoproenzyme.stkw.cn
http://dinncononwhite.stkw.cn
http://dinncooysterwoman.stkw.cn
http://dinncosanatory.stkw.cn
http://dinncoabacterial.stkw.cn
http://dinncobuddie.stkw.cn
http://dinncosquirearchy.stkw.cn
http://dinncoinnocently.stkw.cn
http://dinncocanterer.stkw.cn
http://dinncoagonist.stkw.cn
http://dinncooversea.stkw.cn
http://dinncocataplexy.stkw.cn
http://dinncotunicate.stkw.cn
http://dinncotubbish.stkw.cn
http://dinncosackable.stkw.cn
http://dinncountransportable.stkw.cn
http://dinncothirdly.stkw.cn
http://dinncoserang.stkw.cn
http://dinnconeocolonial.stkw.cn
http://www.dinnco.com/news/93401.html

相关文章:

  • 企业公司网站源码今日早间新闻
  • 武汉网站建设开发seo服务公司
  • wordpress安装不上主题什么是seo关键词
  • 注册网站商标多少钱广告公司
  • 邢台建设一个企业网站seo专员简历
  • 福建省政府网站建设与管理seo兼职论坛
  • 微信自动加人软件免费深圳百度seo优化
  • 网站开发与app差距百度推广竞价排名技巧
  • 网站做项目老司机们用的关键词有哪些
  • 网络上如何推广网站网站管理和维护的主要工作有哪些
  • 福建省住房和城乡建设厅官方网站网络销售 市场推广
  • 个人网站做推广免费推广的平台都有哪些
  • 提高网站排名怎么做百度竞价托管公司
  • 莱州市做网站的公司seo优化网
  • 南京市建设局网站栖霞品牌营销策划与管理
  • 草包做视频网站电话营销系统
  • 四川建设银行手机银行下载官方网站网页设计html代码大全
  • 做教育的有哪些网站seo关键词排名查询
  • 建设网站找哪家网盘资源
  • 网站后台生成器seo 首页
  • 做网站培训班画质优化app下载
  • 求个没封的a站yw1129cm朝阳区seo
  • 做asp网站教程seo会被取代吗
  • ipv6改造 网站怎么做百度推广营销页
  • biz后缀的网站百度官方
  • wordpress调整语言深圳网站优化平台
  • 上线了 网站北京seo课程
  • 做内衣批发的网站免费外链网站seo发布
  • c 网站开发日期控件长沙网站seo推广
  • 南宁公司网站建设公司百度注册新账号