【Python】Numpy扩充数组函数之repeat和tile用法
2014-03-23 15:47
746 查看
用repeat和tile扩充数组元素,例如
官方例子:
转载出处:http://blog.csdn.net/henryghx/article/details/16906235
>>> import numpy as np >>> np.arange(10) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a.repeat(5) array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.tile(a,2) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>>
官方例子:
>>> from numpy import * >>> a=array([10,20]) >>> tile(a,(3,2)) #构造3X2个copy array([[10, 20, 10, 20], [10, 20, 10, 20], [10, 20, 10, 20]]) >>> tile(42.0,(3,2)) array([[ 42., 42.], [ 42., 42.], [ 42., 42.]]) >>>
>>> from numpy import * >>> repeat(7.,4) array([ 7., 7., 7., 7.]) >>> a=array([10,20]) >>> a.repeat([3,2]) array([10, 10, 10, 20, 20]) >>> repeat(a,[3,2]) array([10, 10, 10, 20, 20]) >>> a=array([[10,20],[30,40]]) >>> a.repeat([3,2],axis=0) array([[10, 20], [10, 20], [10, 20], [30, 40], [30, 40]]) >>> a.repeat([3,2],axis=1) array([[10, 10, 10, 20, 20], [30, 30, 30, 40, 40]]) >>>
转载出处:http://blog.csdn.net/henryghx/article/details/16906235
相关文章推荐
- python程序设计基础2:python数据类型习题
- net-snmp启用python模块
- Python:list,tuple,dict
- Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
- 003_004 Python 获取列表中所有歌曲播放时间总和
- 解决python中matplotlib绘图中文显示问题
- Python中range和xrange的用法
- Python中map()函数浅析
- Python中matplotlib绘图介绍
- python 网站自动抠图
- python模板引擎Cheetah的安装
- python程序设计基础2:python数据类型
- Python 连接mysql数据库
- 使用easy_install,ipython报错
- python socket
- 10. python
- Python中dict字典使用方法
- python实现堆栈和队列
- wxPython的Refresh与事件双重响应
- Python学习资源收集