当前位置:网站首页>数据处理之Numpy常用函数表格整理
数据处理之Numpy常用函数表格整理
2022-04-23 05:42:00 【ShuangTwo】
功能 | 具体实现:表中a, b表示数组 |
---|---|
导入numpy库 | import numpy as np |
使用array创建数组 | np.array(([1,2,3],[4,5,6])) |
创建指定数据类型的数组 | np.array([[1,2,3],[4,5,6]], dtype=np.int32) |
创建默认数据类型的数组 | np.arange(5) |
从1到2生成5个浮点数 | np.linspace(1,2,5) |
创建全0数组 | np.zeros((2,3)) |
创建全0数组 | np.ones((2,3)) |
主对角线元素为1其他元素为0 | arr = np.eye(3) |
生成[0,1)之间的随机浮点数 | np.random.random((2,3)) |
生成[0,10)之间的随机整数 | np.random.randint(0,10,(3,2)) |
数组元素的数据类型 | a.dtype |
数组元素占据的内存字节数 | a.dtype.itemsize |
数组元素占据的内存字节数 | a.itemsize |
数组的维度 | a.shape |
数组元素个数 | a.size |
数组行变列,类似于transpose() | a.T |
行变列(类似于矩阵转置) | a.transpose() |
查看数组维度 | a.shape |
返回3行2列的数组 | a.reshape(3,2) |
返回一维数组 | a.ravel() |
最后一个元素 | a[-1] |
返回第2到第5个元素 | a[2:5] |
返回第0到第7个元素,步长为3 | a[:7:3] |
返回逆序的数组 | a[::-1] |
水平合并 | np.hstack((a,b)) |
垂直合并 | np.vstack((a,b)) |
深度合并 | np.dstack((a,b)) |
水平拆分,返回list | np.hsplit(a, 3) |
垂直拆分,返回list | np.vsplit(a, 3) |
深度拆分,返回list | np.dsplit(a, 3) |
数组和常数可以进行四则运算 | a+2 |
数组和数组可以进行四则运算 | a/b |
判断数组是否相等 | (a == b).all() |
所有元素的和 | a.sum() |
所有元素的乘积 | a.prod() |
所有元素的算数平均值 | a.mean() |
所有元素的最大值 | a.max() |
所有元素的最小值 | a.min() |
小于3的元素替换为3,大于4的元素替换为4 | a.clip(3,4) |
返回大于2的元素组成的数组 | a.compress(a>2) |
返回python的list | a.tolist() |
计算方差(元素与均值之差的平方的均值) | a.var() |
计算标准差(方差的算术平方根) | a.std() |
返回数组的最大值和最小值之差 | a.ptp() |
返回最小值在扁平数组中的索引 | a.argmin() |
返回最大值在扁平数组中的索引 | a.argmax() |
返回所有值为2的元素的索引 | np.where(a == 2) |
返回相邻元素的差 | np.diff(a) |
返回对数数组 | np.log(a) |
返回指数数组 | np.exp(a) |
返回开方数组 | np.sqrt(a |
数组排序 | np.msort(a |
返回多个数组中对应位置元素的最大值数组 | np.maximum(a, b) |
返回多个数组中对应位置元素的最小值数组 | np.minimum(a, b) |
对整数实现真正的数学除法运算 | np.true_divide(a, b) |
版权声明
本文为[ShuangTwo]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43356538/article/details/114685487
边栏推荐
- SQL statement simple optimization
- Excel sets row and column colors according to cell contents
- STL function library
- JDBC连接数据库
- 7-10 longest symmetric substring (25 points) (violence problem solution) C language
- MySQL triggers, stored procedures, stored functions
- MySQL transaction
- 一文读懂当前常用的加密技术体系(对称、非对称、信息摘要、数字签名、数字证书、公钥体系)
- Date增加天数
- QT compressed folder
猜你喜欢
Isosceles triangle - the 9th Lanqiao provincial competition - group C
Pilotage growth · ingenuity empowerment -- yonmaster developer training and pilotage plan is fully launched
Batch import of orange single micro service
AcWing 836. Merge set (merge set)
mysql中duplicate key update
第36期《AtCoder Beginner Contest 248 打比赛总结》
2-軟件設計原則
Fletter next generation graphics renderer impaller
PreparedStatement防止SQL注入
Interview Basics
随机推荐
JDBC操作事务
Usage and difference of shellexecute, shellexecuteex and winexec in QT
SQL statement simple optimization
AcWing 836. Merge set (merge set)
SQL语句简单优化
C language - Spoof shutdown applet
橙单微服务之批量导入
数据安全入门产品——数据库审计系统详解
Pol / select / EPO
MySql基础狂神说
PreparedStatement防止SQL注入
io.lettuce.core.RedisCommandExecutionException: ERR wrong number of arguments for ‘auth‘ command
opensips(1)——安装opensips详细流程
创建线程的三种方式
尚硅谷 p290 多态性练习
Frequently asked interview questions - 1 (non technical)
Dwsurvey is an open source questionnaire system. Solve the problem that cannot be run and modify the bug.
手动删除eureka上已经注册的服务
Record a project experience and technologies encountered in the project
字符识别easyocr