python入门运算(shape 、tile 、sum)
来源:互联网 发布:家用健身器材 知乎 编辑:程序博客网 时间:2024/06/05 09:04
本文档简单记录一下python一些入门函数的应用
1.shape函数(求数组或者矩阵的维数)
基本应用就是返回矩阵的行数与列数
//3x3矩阵>>> e = eye(3) >>> e array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> e.shape (3, 3)
//一维矩阵>>> b =array([1,2,3,4]) >>> b.shape (4,)
shape[0],shape[1],分别返回值为矩阵的行数与矩阵的列数
>>> c = array([[1,1],[1,2],[1,3],[1,4]]) >>> carray([[1, 1], [1, 2], [1, 3], [1, 4]])>>> c.shape(4, 2)>>> c.shape[0]4>>> c.shape[1]2
2.tile函数(可以理解为numpy中的一个复制数组的函数)>>> a=[0,1,2]>>> b = tile(a,2)>>> barray([0, 1, 2, 0, 1, 2])
上述用法中,将数组重复两次生成一个新的数组,数组的维数保持不变>>> a=([0,1,2],[2,3,4])>>> tile(a,2)array([[0, 1, 2, 0, 1, 2], [2, 3, 4, 2, 3, 4]])这个例子中,a为二维数组,通过tile(a,2)生成的新数组,将数组a中每个维中的数据重复2次,生成一个维数不变,但数据量变为2倍的新数组
>>> a = [0,1,2]>>> a[0, 1, 2]>>> tile(a,(2,3))array([[0, 1, 2, 0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]])本例中,a为1维数组,tile(a,(2,3))将a数组扩展为2倍维度数组(若a为2维的,则输出为4维的),每个维度中将a重复3次
3.sum函数(求数组的和)
>>> a=np.sum([[0,1,2],[2,1,3]]) >>> a 9求数组的和
>>> a=np.sum([[0,1,2],[2,1,3]],axis=0) >>> a array([2, 2, 5])按列求和
>>> a=np.sum([[0,1,2],[2,1,3]],axis=1) >>> a array([3, 6])按行求和
>>> sum([0,1,2],3) 6将数组求和后,再加3
阅读全文
0 0
- python入门运算(shape 、tile 、sum)
- python shape tile **(幂运算)
- python的tile、shape sum、argsort
- python 中的tile函数,shape函数,sum函数
- Numpy常用函数sum, shape, reshape, argsort, tile,where
- python中的tile函数和sum函数
- python之tile函数,shape函数,argsort函数介绍
- python 求和 .sum(), 和 tile()命令
- python tile
- python tile([],())
- python的numpy包中shape,tile,argsort函数与sorted函数使用方法
- apache-tile学习入门
- Python入门-运算符
- python numpy.tile函数
- Python中的tile函数
- Python&Numpy:tile函数
- python中tile()函数
- tile---python--numpy
- python爬虫(BeautifulSoup)
- python:数据类型
- 多态对象模型
- Git安装及使用文章网址收录
- 自然语言处理
- python入门运算(shape 、tile 、sum)
- VS2017+PCL1.8.1+Cmake(3.6 or later)环境配置
- 第十一周项目二——操作用邻接表存储的图
- chrome文件上传 /获取文件路径c:/fakepath的解决办法
- 深度学习第一课 第四周 深层神经网络用python的实现
- leetcode 446. Arithmetic Slices II
- malloc、free、calloc、realloc的介绍
- maven-assembly-plugin 入门指南
- python2.7出现IOError: [Errno 5] Input/output error