numpy库常用操作汇总
2020-06-19 22:52
183 查看
初学python,整理numpy库中的常用操作,包括矩阵基本属性,矩阵创建,矩阵(二维数组)运算
[code]import numpy as np #矩阵基本属性 #arrange函数生成排列 test_numpy = np.arange(15).reshape(5,3) print(type(test_numpy)) #返回矩阵维数 test_ndim = test_numpy.ndim print(test_ndim) #返回矩阵维度 print(test_numpy.shape) #返回矩阵元素个数 print(test_numpy.size) #返回矩阵元素类型 print(test_numpy.dtype) #返回矩阵每个元素字节数 print(test_numpy.itemsize) #矩阵的创建 #注意array()里是列表或元组 test_mat = np.array([1,2,3,4]) print(test_mat) #2行3列矩阵创建 test_mat = np.array([(1,2,3),(4,5,6)]) #创建全0矩阵 test_zero = np.zeros((3,4),dtype = np.int32) print(test_zero) #创建全1矩阵 test_one = np.ones((3,4),dtype = np.int32) print(test_one) #用法类似np.arange test_space = np.linspace(0,15,17) print(test_space) #创建0,1均匀分布随机矩阵 test_random = np.random.rand(3,3) print(test_random) #创建标准正太分布随机矩阵 test_randn = np.random.randn(3,3) print(test_randn) #数组乘法 a = np.array([(1,2),(3,4)]) b = np.arange(0,4).reshape(2,2) c = np.dot(a,b) print(c)
相关文章推荐
- My sql 操作(不常用)和分析汇总
- 最常用MySQL数据库操作语法语句命令整理汇总
- 常用的 Javascript 操作汇总 (二)
- numpy 常用操作
- 20170726 jQuery操作表格(table)的常用方法、技巧汇总
- 用curl方式操作elasticsearch的常用方法汇总
- python 字符串常用操作汇总
- mysql常用操作汇总
- mysql常用操作汇总(五)
- 【linux】常用操作汇总
- Tortoise SVN 版本控制常用操作汇总(show log)
- JQuery DOM 常用操作汇总
- PHP常用数组操作方法汇总
- 汇总常用的jQuery操作Table tr td方法
- 用前端姿势玩docker【一】Docker通俗理解常用功能汇总与操作埋坑
- python中set常用操作汇总
- Numpy常用操作
- 数据分析——numpy库常用基本操作
- Eclipse的一些常用操作和快捷键汇总
- MS SQL的一些经典常用操作语句汇总