NNDL练习——Numpy的简单使用
2024-08-25 06:53:19
Numpy导入
import numpy as np
数组/矩阵的创建
a=np.array([1,2,3])
b=np.array([[1,2],[3,4]])
c=np.zeros((1,2),dtype=int) ##全0矩阵
d=np.ones((1,2)) ##全1矩阵
e=np.identity(4) ##4*4单位矩阵
f=np.random.random((3,2)) ##3*2随机矩阵
属性功能
type(a) ##类型
a.dtype ##数据类型
a.shape ##形状
a[0]
a[0,0] ##元素
##加减乘除,对应位置的元素做运算
a+b
np.add(a,b)
a*b
np.multiply(a,b)
a-b
np.subtract(a,b)
a/b
np.divide(a,b)
##矩阵乘法
np.dot(a,b)
##取a的倒数第二行和最后一行
b=a[-2:,:]
##开方
np.sqrt(a)
a**(1/2)
##求e
np.exp(a)
##求和
np.sum(a)
##算每一列和
np.sum(a,axis=0)
##算每一行和
np.sum(a,axis=1)
##求平均数
np.mean(a)
##算每一列平均数
np.mean(a,axis=0)
##算每一行平均数
np.mean(a,axis=1)
##转置
a.T
##值最大的下标
np.argmax(a)
##每一列值最大的下标
np.argmax(a,axis=0)
##每一行值最大的下标
np.argmax(a,axis=1)
##0~3pi,步长0.1的数组
x=np.arange(0,3*np.pi,0.1)
##sin
np.sin(x)
##cos
np.cos(x)
注记
np.nan不可比较大小,返回false
最新文章
- jprofiler_监控远程linux服务器的JVM进程(实践)
- oslo.messaging 1.8.0 bug fix and blueprint
- HBase概念学习(十)HBase与MongDB等NoSQL数据库对照
- Row Border in DataGrid 表格边框
- TypeScript学习指南第二章--接口(Interface)
- gitlab hooks
- discuz门户文章页面模板修改
- day16<;集合框架+>;
- 正则表达式&;常用JS校验
- 树链剖分( 洛谷P3384 )
- Java 常用List集合使用场景分析
- HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]
- 配置nginx1.8支持thinkPHP3.2 pathinfo模式
- centos 7使用docker安装lnmp和redis环境
- go语言之进阶篇方法的继承
- Definitaion of &#39;utsname&#39; must be imported from module &#39;Darwin.POSIX.sys.utsname&#39; before it is required
- mapreduce 只使用Mapper往多个hbase表中写数据
- Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.0.1.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempt
- .net core iis 502.5
- Leetcode题库——16.最接近的三数之和