python的numpy包中shape,tile,argsort函数与sorted函数使用方法
来源:互联网 发布:域名劫持查询 编辑:程序博客网 时间:2024/06/05 02:38
一:shape
功能:shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度。它的输入参数可以使一个整数表示维度,也可以是一个矩阵
例:(以下都已导入numpy模块)
1.一维矩阵[1]返回值为(1,)
>>>shape([1])(1,)
2.二维矩阵,返回两个值
>>>shape([[1],[2]])(2,1)
3.一个单独的数字,返回值为空
>>>shape(3)()
4.如果用于矩阵中读取矩阵的的形状
>>>e=numpy.eye(3)>>>earray([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]])>>> e.shape(3, 3)
5.读取矩阵的第一维长度用
shape[0]
二:tile
函数形式: tile(A,rep)
功能:重复A的各个维度
例:(以下都已导入numpy模块)
1.重复一维 >>> np.tile([1,2],2)
array([1, 2, 1, 2])
2.重复二维
重复顺序为: [1,2] => [[1,2] , [1,2]] => [[1,2,1,2] , [1,2,1,2]]
>>> np.tile([1,2],(2,2))array([[1, 2, 1, 2], [1, 2, 1, 2]])
3.重复多维
重复顺序为: [1,2] => [[1,2] , [1,2]] => [[[1,2],[1,2]] , [[1,2],[1,2]]] => [[[1,2,1,2,1,2],[1,2,1,2,1,2]] , [[1,2,1,2,1,2],[1,2,1,2,1,2]]]
>>> np.tile([1,2],(2,2,2))array([[[1, 2, 1, 2], [1, 2, 1, 2]], [[1, 2, 1, 2], [1, 2, 1, 2]]])
三:argsort
功能:argsort()函数是将x中的元素从小到大排列,提取其对应的index(索引),然后输出到y(y为数组)
例:
>>> a=np.array([1,2,3,4])>>> a.argsort()array([0, 1, 2, 3], dtype=int64)
四:sorted()与sort的区别
功能:list排序函数
区别:两者均作为list排序函数,但sorted()方法返回一个新的list,新的list中的元素升序排列。
而list.sort()方法排序的话,list本身将被修改。两者互有优劣
- python的numpy包中shape,tile,argsort函数与sorted函数使用方法
- Numpy常用函数sum, shape, reshape, argsort, tile,where
- python之tile函数,shape函数,argsort函数介绍
- python中numpy的argsort函数讲解
- 【Python】numpy中argsort函数的使用
- Python中Numpy的tile函数用法以及operator.itemgetter函数和sorted函数
- numpy的argsort和sum和tile函数
- [Python]numpy中tile函数的用法
- 【Python】numpy中tile函数的使用
- NumPy 中argsort函数
- python的tile、shape sum、argsort
- Python-Numpy的tile函数
- numpy中argsort函数的用法
- Numpy中argsort函数的简单用法
- 浅述numpy中argsort()函数的用法
- numpy中argsort()函数的使用
- python numpy.tile函数
- Python&Numpy:tile函数
- 中国剩余定理
- 接口实现类方法的回调
- Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版(四)调整 App.vue 和 router 路由
- char *s 和 char s[] 的区别
- 堆排序算法分析与实现
- python的numpy包中shape,tile,argsort函数与sorted函数使用方法
- UVALive 6694
- 【LeetCode】Longest Palindrome(最长回文串)
- vs2015 安装及番茄插件使用
- Gtest框架进行Windows API测试:CreateFile和枚举文件
- Java经典算法题(一)
- KFC游记——生活中的网络安全篇一
- MacOS下彻底删除多余的Python版本
- java 异常,java,异常