This is an auto-generated version of Numpy Example List with added documentation from doc strings and arguments specification for methods and functions of Numpy 1.0.4.
Please do not edit this page directly. To update this page just follow the instructions.
Contents
- ...
- []
- T
- abs()
- absolute()
- accumulate
- add()
- alen()
- all()
- allclose()
- alltrue()
- alterdot()
- amax()
- amin()
- angle()
- any()
- append()
- apply_along_axis()
- apply_over_axes()
- arange()
- arccos()
- arccosh()
- arcsin()
- arcsinh()
- arctan()
- arctan2()
- arctanh()
- argmax()
- argmin()
- argsort()
- argwhere()
- around()
- array()
- array2string()
- array_equal()
- array_equiv()
- array_repr()
- array_split()
- array_str()
- arrayrange
- asanyarray()
- asarray()
- asarray_chkfinite()
- ascontiguousarray()
- asfarray()
- asfortranarray()
- asmatrix()
- asscalar()
- astype()
- atleast_1d()
- atleast_2d()
- atleast_3d()
- average()
- bartlett()
- base_repr()
- beta()
- binary_repr()
- bincount()
- binomial()
- bitwise_and()
- bitwise_not()
- bitwise_or()
- bitwise_xor()
- blackman()
- bmat()
- broadcast()
- byte_bounds()
- bytes()
- byteswap()
- c_
- cast[]()
- can_cast()
- ceil()
- choose()
- clip()
- column_stack()
- common_type()
- compare_chararrays()
- compress()
- concatenate()
- conj()
- conjugate()
- convolve()
- copy()
- corrcoef()
- correlate()
- cos()
- cosh()
- cov()
- cross()
- cumprod()
- cumproduct()
- cumsum()
- delete()
- deprecate()
- diag()
- diagflat()
- diagonal()
- diff()
- digitize()
- disp()
- divide()
- dot()
- dsplit()
- dstack()
- dtype() or .dtype
- dump()
- dumps()
- ediff1d()
- empty()
- empty_like()
- equal()
- exp()
- expand_dims()
- expm1()
- extract()
- eye()
- fabs()
- fastCopyAndTranspose()
- fft
- fftfreq
- fftshift
- fill()
- finfo()
- fix()
- flat
- flatnonzero()
- flatten()
- fliplr()
- flipud()
- floor()
- floor_divide()
- fmod()
- frexp()
- fromarrays()
- frombuffer()
- fromfile()
- fromfunction()
- fromiter()
- frompyfunc()
- fromrecords()
- fromstring()
- generic()
- get_array_wrap()
- get_include()
- get_numarray_include()
- get_numpy_include()
- get_printoptions()
- getbuffer()
- getbufsize()
- geterr()
- geterrcall()
- geterrobj()
- getfield()
- gradient()
- greater()
- greater_equal()
- gumbel()
- hamming()
- hanning()
- histogram()
- histogram2d()
- histogramdd()
- hsplit()
- hstack()
- hypot()
- i0()
- identity()
- ifft
- imag() or .imag
- index_exp
- indices()
- inf
- info() or .info
- inner()
- insert()
- int_asbuffer()
- interp()
- intersect1d()
- intersect1d_nu()
- inv()
- invert()
- iscomplex()
- iscomplexobj()
- isfinite()
- isfortran()
- isinf()
- isnan()
- isneginf()
- isposinf()
- isreal()
- isrealobj()
- isscalar()
- issctype()
- issubclass_()
- issubdtype()
- issubsctype()
- item()
- itemset()
- iterable()
- ix_()
- kaiser()
- kron()
- ldexp()
- left_shift()
- less()
- less_equal()
- lexsort()
- linspace()
- load()
- loads()
- loadtxt()
- log()
- log10()
- log1p()
- log2()
- logical_and()
- logical_not()
- logical_or()
- logical_xor()
- logspace()
- lstsq()
- mat()
- matrix()
- max()
- maximum()
- maximum_sctype()
- may_share_memory()
- mean()
- median()
- meshgrid()
- mgrid
- min()
- minimum()
- mintypecode()
- mod()
- modf()
- msort()
- multiply()
- nan
- nan_to_num()
- nanargmax()
- nanargmin()
- nanmax()
- nanmin()
- nansum()
- ndenumerate()
- ndim() or .ndim
- ndindex()
- negative()
- newaxis
- newbuffer()
- newbyteorder()
- nonzero()
- not_equal()
- obj2sctype()
- ogrid
- ones()
- ones_like()
- outer()
- permutation()
- piecewise()
- pinv()
- pkgload()
- place()
- poisson()
- poly()
- poly1d()
- polyadd()
- polyder()
- polydiv()
- polyfit()
- polyint()
- polymul()
- polysub()
- polyval()
- power()
- prod()
- product()
- ptp()
- put()
- putmask()
- r_
- randint()
- random_integers()
- random_sample()
- ranf()
- rank()
- ravel()
- real() or .real
- real_if_close()
- recarray()
- reciprocal()
- reduce
- remainder()
- repeat()
- require()
- reshape()
- resize()
- restoredot()
- right_shift()
- rint()
- roll()
- rollaxis()
- roots()
- rot90()
- round()
- round_()
- row_stack()
- s_
- sample()
- savetxt()
- sctype2char()
- searchsorted()
- seed()
- select()
- set_numeric_ops()
- set_printoptions()
- set_string_function()
- setbufsize()
- setdiff1d()
- seterr()
- seterrcall()
- seterrobj()
- setfield()
- setflags()
- setmember1d()
- setxor1d()
- shape() or .shape
- show_config()
- shuffle()
- sign()
- signbit()
- sin()
- sinc()
- sinh()
- size() or .size
- slice
- solve()
- sometrue()
- sort()
- sort_complex()
- source()
- split()
- sqrt()
- square()
- squeeze()
- standard_normal()
- std()
- subtract()
- sum()
- svd()
- swapaxes()
- take()
- tan()
- tanh()
- tensordot()
- test()
- tile()
- tofile()
- tolist()
- tostring()
- trace()
- transpose()
- trapz()
- tri()
- tril()
- trim_zeros()
- triu()
- true_divide()
- typeDict
- typename()
- uniform()
- union1d()
- unique()
- unique1d()
- unravel_index()
- unwrap()
- vander()
- var()
- vdot()
- vectorize()
- view()
- vonmises()
- vsplit()
- vstack()
- weibull()
- where()
- who()
- zeros()
- zeros_like()
...
>>> from numpy import *
>>> a = arange(12)
>>> a = a.reshape(3,2,2)
>>> print a
[[[ 0 1]
[ 2 3]]
[[ 4 5]
[ 6 7]]
[[ 8 9]
[10 11]]]
>>> a[...,0] # same as a[:,:,0]
array([[ 0, 2],
[ 4, 6],
[ 8, 10]])
>>> a[1:,...] # same as a[1:,:,:] or just a[1:]
array([[[ 4, 5],
[ 6, 7]],
[[ 8, 9],
[10, 11]]])
[]
>>> from numpy import *
>>> a = array([ [ 0, 1, 2, 3, 4],
... [10,11,12,13,14],
... [20,21,22,23,24],
... [30,31,32,33,34] ])
>>>
>>> a[0,0] # indices start by zero
0
>>> a[-1] # last row
array([30, 31, 32, 33, 34])
>>> a[1:3,1:4] # subarray
array([[11, 12, 13],
[21, 22, 23]])
>>>
>>> i = array([0,1,2,1]) # array of indices for the first axis
>>> j = array([1,2,3,4]) # array of indices for the second axis
>>> a[i,j]
array([ 1, 12, 23, 14])
>>>
>>> a[a<13] # boolean indexing
array([ 0, 1, 2, 3, 4, 10, 11, 12])
>>>
>>> b1 = array( [True,False,True,False] ) # boolean row selector
>>> a[b1,:]
array([[ 0, 1, 2, 3, 4],
[20, 21, 22, 23, 24]])
>>>
>>> b2 = array( [False,True,True,False,True] ) # boolean column selector
>>> a[:,b2]
array([[ 1, 2, 4],
[11, 12, 14],
[21, 22, 24],
[31, 32, 34]])
See also: ..., newaxis, ix_, indices, nonzero, where, slice
T
ndarray.T
Same as self.transpose() except self is returned for self.ndim < 2.
>>> from numpy import *
>>> x = array([[1.,2.],[3.,4.]])
>>> x
array([[ 1., 2.],
[ 3., 4.]])
>>> x.T # shortcut for transpose()
array([[ 1., 3.],
[ 2., 4.]])
See also: transpose
abs()
numpy.abs(...)
y = absolute(x) takes |x| elementwise.
>>> from numpy import *
>>> abs(-1)
1
>>> abs(array([-1.2, 1.2]))
array([ 1.2, 1.2])
>>> abs(1.2+1j)
1.5620499351813308
absolute()
numpy.absolute(...)
y = absolute(x) takes |x| elementwise.
Synonym for abs()
See abs
accumulate
>>> from numpy import *
>>> add.accumulate(array([1.,2.,3.,4.])) # like reduce() but also gives intermediate results
array([ 1., 3., 6., 10.])
>>> array([1., 1.+2., (1.+2.)+3., ((1.+2.)+3.)+4.]) # this is what it computed
array([ 1., 3., 6., 10.])
>>> multiply.accumulate(array([1.,2.,3.,4.])) # works also with other operands
array([ 1., 2., 6., 24.])
>>> array([1., 1.*2., (1.*2.)*3., ((1.*2.)*3.)*4.]) # this is what it computed
array([ 1., 2., 6., 24.])
>>> add.accumulate(array([[1,2,3],[4,5,6]]), axis = 0) # accumulate every column separately
array([[1, 2, 3],
[5, 7, 9]])
>>> add.accumulate(array([[1,2,3],[4,5,6]]), axis = 1) # accumulate every row separately
array([[ 1, 3, 6],
[ 4, 9, 15]])
See also: reduce, cumprod, cumsum
add()
numpy.add(...)
y = add(x1,x2) adds the arguments elementwise.
>>> from numpy import *
>>> add(array([-1.2, 1.2]), array([1,3]))
array([-0.2, 4.2])
>>> array([-1.2, 1.2]) + array([1,3])
array([-0.2, 4.2])
alen()
numpy.alen(a)
Return the length of a Python object interpreted as an array of at least 1 dimension. Blah, Blah.
all()
numpy.all(a, axis=None, out=None)
Return true if all elements of a are true:
*See Also*:
`ndarray.all` : equivalent method
`alltrue` : equivalent function
ndarray.all(...)
a.all(axis=None)
>>> from numpy import *
>>> a = array([True, False, True])
>>> a.all() # if all elements of a are True: return True; otherwise False
False
>>> all(a) # this form also exists
False
>>> a = array([1,2,3])
>>> all(a > 0) # equivalent to (a > 0).all()
True
See also: any, alltrue, sometrue
allclose()
numpy.allclose(a, b, rtol=1.0000000000000001e-005, atol=1e-008)
Returns True if all components of a and b are equal subject to given tolerances. The relative error rtol must be positive and << 1.0 The absolute error atol usually comes into play for those elements of b that are very small or zero; it says how small a must be also.
>>> allclose(array([1e10,1e-7]), array([1.00001e10,1e-8]))
False
>>> allclose(array([1e10,1e-8]), array([1.00001e10,1e-9]))
True
>>> allclose(array([1e10,1e-8]), array([1.0001e10,1e-9]))
False
alltrue()
numpy.alltrue(a, axis=None, out=None)
Perform a logical_and over the given axis.
*See Also*:
`ndarray.all` : equivalent method
`all` : equivalent function
>>> from numpy import *
>>> b = array([True, False, True, True])
>>> alltrue(b)
False
>>> a = array([1, 5, 2, 7])
>>> alltrue(a >= 5)
False
alterdot()
numpy.alterdot(...)
alterdot() changes all dot functions to use blas.
amax()
numpy.amax(a, axis=None, out=None)
Return the maximum of 'a' along dimension axis. Blah, Blah.
amin()
numpy.amin(a, axis=None, out=None)
Return the minimum of a along dimension axis. Blah, Blah.
angle()
numpy.angle(z, deg=0)
Return the angle of the complex argument z.
>>> from numpy import *
>>> angle(1+1j) # in radians
0.78539816339744828
>>> angle(1+1j,deg=True) # in degrees
45.0
any()
numpy.any(a, axis=None, out=None)
Return true if any elements of a are true.
*See Also*:
`ndarray.any` : equivalent method
ndarray.any(...)
a.any(axis=None, out=None)
>>> from numpy import *
>>> a = array([True, False, True])
>>> a.any() # gives True if at least 1 element of a is True, otherwise False
True
>>> any(a) # this form also exists
True
>>> a = array([1,2,3])
>>> (a >= 1).any() # equivalent to any(a >= 1)
True
See also: all, alltrue, sometrue
append()
numpy.append(arr, values, axis=None)
Append to the end of an array along axis (ravel first if None)
>>> from numpy import *
>>> a = array([10,20,30,40])
>>> append(a,50)
array([10, 20, 30, 40, 50])
>>> append(a,[50,60])
array([10, 20, 30, 40, 50, 60])
>>> a = array([[10,20,30],[40,50,60],[70,80,90]])
>>> append(a,[[15,15,15]],axis=0)
array([[10, 20, 30],
[40, 50, 60],
[70, 80, 90],
[15, 15, 15]])
>>> append(a,[[15],[15],[15]],axis=1)
array([[10, 20, 30, 15],
[40, 50, 60, 15],
[70, 80, 90, 15]])
See also: insert, delete, concatenate
apply_along_axis()
numpy.apply_along_axis(func1d, axis, arr, *args)
Execute func1d(arr[i],*args) where func1d takes 1-D arrays and arr is an N-d array. i varies so as to apply the function along the given axis for each 1-d subarray in arr.
>>> from numpy import *
>>> def myfunc(a): # function works on a 1d arrays, takes the average of the 1st an last element
... return (a[0]+a[-1])/2
...
>>> b = array([[1,2,3],[4,5,6],[7,8,9]])
>>> apply_along_axis(myfunc,0,b) # apply myfunc to each column (axis=0) of b
array([4, 5, 6])
>>> apply_along_axis(myfunc,1,b) # apply myfunc to each row (axis=1) of b
array([2, 5, 8])
See also: apply_over_axes, vectorize
apply_over_axes()
numpy.apply_over_axes(func, a, axes)
Apply a function repeatedly over multiple axes, keeping the same shape for the resulting array. func is called as res = func(a, axis). The result is assumed to be either the same shape as a or have one less dimension. This call is repeated for each axis in the axes sequence.
>>> from numpy import *
>>> a = arange(24).reshape(2,3,4) # a has 3 axes: 0,1 and 2
>>> a
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
>>> apply_over_axes(sum, a, [0,2]) # sum over all axes except axis=1, result has same shape as original
array([[[ 60]