1、矩阵

>>> import numpy as np>>> a = np.mat([[1,2,3],[4,5,6],[7,8,9]])  # 3行3列
>>> a
matrix([[1, 2, 3],[4, 5, 6],[7, 8, 9]])
>>> a[0,1]   # 取第一行第二个数据
2
>>> a[0,:]    # 取第一行的数据
matrix([[1, 2, 3]])>>> b = np.mat([[8,5,3],[2,9,6],[7,1,4]])
>>> b
matrix([[8, 5, 3],[2, 9, 6],[7, 1, 4]])
>>> b.shape   # 获得矩阵的行列数
(3, 3)
>>> b.shape[0]   # 获得矩阵的行数
3
>>> b.shape[1]   # 获得矩阵的列数
3
>>> b.sort()     # 对每行排序
>>> b
matrix([[3, 5, 8],[2, 6, 9],[1, 4, 7]])# 矩阵相乘(线性代数)
>>> a = np.mat([[1,2,3],[4,5,6],[7,8,9]])
>>> b = np.mat([[8,5,3],[2,9,6],[7,1,4]])
>>> a*b
matrix([[ 33,  26,  27],[ 84,  71,  66],[135, 116, 105]])
>>> np.matmul(a,b)
matrix([[ 33,  26,  27],[ 84,  71,  66],[135, 116, 105]])
>>> np.dot(a,b)
matrix([[ 33,  26,  27],[ 84,  71,  66],[135, 116, 105]])#矩阵点乘(对应位置相乘)
>>> a = np.mat([[1,2,3],[4,5,6],[7,8,9]])
>>> b = np.mat([[8,5,3],[2,9,6],[7,1,4]])
>>> np.multiply(a, b)
matrix([[ 8, 10,  9],[ 8, 45, 36],[49,  8, 36]])# 矩阵转置
>>> a = np.mat([[1,2,3],[4,5,6],[7,8,9]])
>>> a.T
matrix([[1, 4, 7],[2, 5, 8],[3, 6, 9]])
>>> np.transpose(a)
matrix([[1, 4, 7],[2, 5, 8],[3, 6, 9]])# 矩阵求逆
>>> a = np.mat([[0.5,1],[1,0.5]])
>>> a.I
matrix([[-0.66666667,  1.33333333],[ 1.33333333, -0.66666667]])
#!!!若a为奇异矩阵,则不可逆,a.I将会报错

2、三角函数

>>> import numpy as np
#cos, cosh, sin sinh, tan, tanh,arccos, arccosh, arcsin, arcsinh, arctan, arctanh
>>> a = np.sin(90*np.pi/180)  # sin函数计算时,括号中为弧度
>>> a
1.0
>>> np.degrees(np.pi/2)  # 弧度转度
90.0
>>> np.radians(180)    # 度转弧度
3.141592653589793>>> import math
#sin,cos,tan,asin,acos,atan,atan2,sinh,cosh,tanh,asinh,acosh,atanh
>>> math.sin(math.pi/2)
1.0
>>> math.cos(0)
1.0
>>> math.tan(math.pi/6)
0.5773502691896257>>> math.degrees(math.pi/2)    # 弧度转度
90.0
>>> math.radians(180)          # 度转弧度
3.141592653589793

python 矩阵和三角函数相关推荐

  1. python中的[:-1] [:,:-1] python矩阵numpy中array的冒号 逗号

    如何理解[:-1]  [:,:-1] data = np.loadtxt('data.csv', delimiter = ',')     X = data[:,:-1]    #取所有行,取列到倒数 ...

  2. python 矩阵中的冒号 逗号

    python 矩阵中的冒号 逗号 https://blog.csdn.net/Strive_0902/article/details/78225691?utm_source=blogxgwz0 pyt ...

  3. python矩阵相加_【python矩阵相加怎么做,这可是证明python功能的大好机会】- 环球网校...

    [摘要]今天的python实践内容是为了让大家了解python矩阵相加方法,对代码编程有个感性的认知.也好让大家能够理性选择,不要盲目跟从,选择适合自己当前阶段的学习内容,循序渐进,以兴趣自我探索为向 ...

  4. python矩阵中插入矩阵_Python | 矩阵的痕迹

    python矩阵中插入矩阵 The sum of diagonal elements of a matrix is commonly known as the trace of the matrix. ...

  5. python矩阵转置_Python 矩阵转置的几种方法小结

    我就废话不多说了,直接上代码吧! #Python的matrix转置 matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] def printmatrix(m): fo ...

  6. python矩阵_Python矩阵

    python矩阵 In this tutorial we will learn about Python Matrix. In our previous tutorial we learnt abou ...

  7. python 矩阵求转置、行列式、迹、求逆

    python 矩阵求解 import numpy as np 1.转置 a=np.eye(3) print(a.T) 2.各列元素和 print(sum(a)) 3.求矩阵行列式 print(np.l ...

  8. python如何使用三角函数_Python中计算三角函数之cos()方法的使用简介

    Python中计算三角函数之cos()方法的使用简介 这篇文章主要介绍了Python中计算三角函数之cos()方法的使用简介,是Python入门的基础知识,需要的朋友可以参考下 cos()方法返回x弧 ...

  9. python 矩阵转置

    python 矩阵转置 matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ] 以下实例将3X4的矩阵列表转 ...

最新文章

  1. SAP-ABAP DESCRIBE FIELD 用法
  2. POPUP_GET_VALUES
  3. (3.1)HarmonyOS鸿蒙单击事件4种写法
  4. jspdf html转换pdf,使用jspdf将HTML转换为pdf时出错
  5. 为SharePoint Services (SPS)设置文件图标
  6. PHP之安装Pear
  7. Android常用代码集
  8. VM12 虚拟机使用桥接模式却连不上网的解决方法(图文讲解)
  9. js 中的 let 关键字
  10. js中Date函数获取今天星期几的方法
  11. python爬虫爬取豆瓣电影评分排行榜前n名的前n页影评
  12. Ansys/Abaqus/nbsp;热应力分析.20…
  13. 竖屏java转横屏_android设置横屏和竖屏的方法
  14. iPad浏览器HTML5性能测试
  15. 水星MW300R无线路由器的设置方法
  16. sheetJS+input——实现vue导入excel文件,并判断文件内容是否正确——基础积累
  17. 基于墨刀实现的原型系统:一款简易的读书软件
  18. 计算机可以辅助英语写作吗,计算机辅助下的英语写作教学_问答库
  19. 新疆计算机应用能力考试,新疆6类人群免于计算机应用能力考试
  20. 「 计算机网络 」TCP的粘包拆包问题

热门文章

  1. 【DC系列】DC-4靶机渗透练习
  2. 画出漂亮的神经网络图,神经网络可视化工具集锦
  3. 每一次严重事故都是可以预测的
  4. 后台站点-菜单管理功能(一)
  5. 拆分句子成为一个个单词,并统计各个单词的数量
  6. Java开发面试(持续更新)
  7. CATIA P3 V5-6R2018 软件下载
  8. Maple学习笔记——数学计算与数据处理
  9. 微信开发之服务号设置
  10. 华为nova2连不上计算机,华为nova2正式发布,连个5G WIFI都不支持?