One-dimensional arrays can be indexed, sliced and iterated over, much like lists and other Pythonsequences.
>>> a = arange(10)**3
>>> a
array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729])
>>> a[2]
8
>>> a[2:5]
array([ 8, 27, 64])
>>> a[:6:2] = -1000 # equivalent to a[0:6:2] = -1000; from start to position 6, exclusive, set every 2nd element to -1000
>>> a
array([-1000, 1, -1000, 27, -1000, 125, 216, 343, 512, 729])
>>> a[ : :-1] # reversed a
array([ 729, 512, 343, 216, 125, -1000, 27, -1000, 1, -1000])
>>> for i in a:
... print i**(1/3.),
...
nan 1.0 nan 3.0 nan 5.0 6.0 7.0 8.0 9.0
Multidimensional arrays can have one index per axis. These indices are given in a tuple separated bycommas:
>>> def f(x,y):
... return 10*x+y
...
>>> b = fromfunction(f,(5,4),dtype=int)
>>> b
array([[ 0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23],
[30, 31, 32, 33],
[40, 41, 42, 43]])
>>> b[2,3]
23
>>> b[0:5, 1] # each row in the second column of b
array([ 1, 11, 21, 31, 41])
>>> b[ : ,1] # equivalent to the previous example
array([ 1, 11, 21, 31, 41])
>>> b[1:3, : ] # each column in the second and third row of b
array([[10, 11, 12, 13],
[20, 21, 22, 23]])
When fewer indices are provided than the number of axes, the missing indices are considered complete
Tentative NumPy Tutorial -_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 Tentative NumPy Tutorial -_计算机软件及应用_IT/计算机_...
See Also: numpy.doc.ufuncs Section “Output arguments” Examples >>> a = np.arange(10) >>> np.clip(a, 1, 8) array([1, 1, 2, 3, 4, 5,...
NumPy使用手记_计算机软件及应用_IT/计算机_专业资料。NumPy 使用手记[z] Posted...Tentative NumPy Tutori... 16页 免费 喜欢此文档的还喜欢 numpy官方参考手册 ...
Python 教程:numpy 的基本介绍 2012-04-10 12:58 作者: bukunu 来源: 本站 浏览: 1,430 views 我要评论(1 条) 字号: 大中小 摘要: 标准安装的 Python ...
4、安装 numpy numpy 和 scipy 的安装过程都要显式的指明所用 fortran 编译器的类型,而且要与前面编译 atlas 时一致(在本文中即:gfortran),这一点非常重要,...
numpy学习_计算机软件及应用_IT/计算机_专业资料。1. tile 函数 tile 函数是模板...NumPy 中的多维迭代器 暂无评价 31页 免费 Tentative NumPy Tutori... 暂无评...
安装python numpy_计算机软件及应用_IT/计算机_专业资料。安装python numpy,出现问题,如何解决。安装python numpy 研究 python-nltk 时,需要安装 numpy。 采用下面的...
Python之路numpy用法_计算机软件及应用_IT/计算机_专业资料。Python 之路——numpy 各函数简介之生成数组函数(Array creation routines) 1、empty(shape[, dtype, ...
numpy各函数简介之生成数组函数_计算机软件及应用_IT/计算机_专业资料。numpy 各函数简介之生成数组函数 1. empty(shape[, dtype, order]): 依据给定形状和类型(...
非root权限安装numpy和scipy_生物学_自然科学_专业资料。linux上可行。Install Numpy and Scipy on CentOS without Root Privilege Sometimes you want to install Nu...
热门文档