Home | Trees | Index | Help |
|
---|
Package numpy :: Class ndarray |
|
object
--+
|
ndarray
BBox
An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type-descriptor object details the data-type in an array (including byteorder and any fields). An array can be constructed using the numpy.array command. Arrays are sequence, mapping and numeric objects. More information is available in the numpy module and by looking at the methods and attributes of an array. ndarray.__new__(subtype, shape=, dtype=float, buffer=None, offset=0, strides=None, order=None) There are two modes of creating an array using __new__: 1) If buffer is None, then only shape, dtype, and order are used 2) If buffer is an object exporting the buffer interface, then all keywords are interpreted. The dtype parameter can be any object that can be interpreted as a numpy.dtype object. No __init__ method is needed because the array is fully initialized after the __new__ method.
Method Summary | |
---|---|
__abs__(x)
Return abs(x)... | |
__add__(x,
y)
Return x+y... | |
__and__(x,
y)
Return x&y... | |
a.__array__(|dtype) -> reference if type unchanged, copy otherwise. | |
__array_wrap__(a,
obj)
Return object of same type as a from ndarray obj. | |
__contains__(x,
y)
Return y in x... | |
a.__copy__(|order) -> copy, possibly with different order. | |
Used if copy.deepcopy is called on an array. | |
__delitem__(x,
y)
Return del x[y]... | |
Use of negative indices is not supported. | |
__div__(x,
y)
Return x/y... | |
__divmod__(x,
y)
Return divmod(x, y)... | |
__eq__(x,
y)
Return x==y... | |
__float__(x)
Return float(x)... | |
__floordiv__(x,
y)
Return x//y... | |
__ge__(x,
y)
Return x>=y... | |
__getitem__(x,
y)
Return x[y]... | |
Use of negative indices is not supported. | |
__gt__(x,
y)
Return x>y... | |
__hex__(x)
Return hex(x)... | |
__iadd__(x,
y)
Return x+y... | |
__iand__(x,
y)
Return x&y... | |
__idiv__(x,
y)
Return x/y... | |
__ifloordiv__(x,
y)
Return x//y... | |
__ilshift__(x,
y)
Return x<<y... | |
__imod__(x,
y)
Return x%y... | |
__imul__(x,
y)
Return x*y... | |
x[y:z] <==> x[y.__index__():z.__index__()] | |
__int__(x)
Return int(x)... | |
__invert__(x)
Return ~x... | |
__ior__(x,
y)
Return x|y... | |
__ipow__(x,
y)
Return x**y... | |
__irshift__(x,
y)
Return x>>y... | |
__isub__(x,
y)
Return x-y... | |
__iter__(x)
Return iter(x)... | |
__itruediv__(x,
y)
Return x/y... | |
__ixor__(x,
y)
Return x^y... | |
__le__(x,
y)
Return x<=y... | |
__len__(x)
Return len(x)... | |
__long__(x)
Return long(x)... | |
__lshift__(x,
y)
Return x<<y... | |
__lt__(x,
y)
Return x<y... | |
__mod__(x,
y)
Return x%y... | |
__mul__(x,
y)
Return x*y... | |
__ne__(x,
y)
Return x!=y... | |
__neg__(x)
Return -x... | |
__new__(T,
S,
...)
Return a new object with type S, a subtype of T... | |
__nonzero__(x)
Return x != 0... | |
__oct__(x)
Return oct(x)... | |
__or__(x,
y)
Return x|y... | |
__pos__(x)
Return +x... | |
__pow__(x,
y,
z)
Return pow(x, y[, z])... | |
__radd__(x,
y)
Return y+x... | |
__rand__(x,
y)
Return y&x... | |
__rdiv__(x,
y)
Return y/x... | |
__rdivmod__(x,
y)
Return divmod(y, x)... | |
For pickling. | |
__repr__(x)
Return repr(x)... | |
__rfloordiv__(x,
y)
Return y//x... | |
__rlshift__(x,
y)
Return y<<x... | |
__rmod__(x,
y)
Return y%x... | |
__rmul__(x,
y)
Return y*x... | |
__ror__(x,
y)
Return y|x... | |
__rpow__(y,
x,
z)
Return pow(x, y[, z])... | |
__rrshift__(x,
y)
Return y>>x... | |
__rshift__(x,
y)
Return x>>y... | |
__rsub__(x,
y)
Return y-x... | |
__rtruediv__(x,
y)
Return y/x... | |
__rxor__(x,
y)
Return y^x... | |
__setitem__(x,
i,
y)
Return x[i]=y... | |
Use of negative indices is not supported. | |
For unpickling. | |
__str__(x)
Return str(x)... | |
__sub__(x,
y)
Return x-y... | |
__truediv__(x,
y)
Return x/y... | |
__xor__(x,
y)
Return x^y... | |
all(a,
axis)
| |
any(a,
axis,
out)
| |
argmax(a,
axis,
out)
| |
argmin(a,
axis,
out)
| |
Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. | |
Cast array m to type t. | |
Swap the bytes in the array. | |
Return an array that merges the b_i arrays together using 'a' as the index The b_i arrays and 'a' must all be broadcastable to the same shape. | |
clip(a,
min,
max,
out)
| |
compress(a,
condition,
axis,
out)
| |
conj(a)
| |
conjugate(a)
| |
a.copy(|order) -> copy, possibly with different order. | |
cumprod(a,
axis,
dtype)
| |
cumsum(a,
axis,
dtype,
out)
| |
If a is 2-d, return the diagonal of self with the given offset, i.e., the collection of elements of the form a[i,i+offset]. | |
a.dump(file) Dump a pickle of the array to the specified file. | |
a.dumps() returns the pickle of the array as a string. | |
Fill the array with the scalar value. | |
a.flatten([fortran]) return a 1-d array (always copy) | |
Returns a field of the given array as a certain type. | |
Copy the first element of array to a standard Python scalar and return it. | |
itemset(...)
| |
max(a,
axis)
| |
Returns the average of the array elements. | |
min(a,
axis)
| |
a.newbyteorder(<byteorder>) is equivalent to a.view(a.dtype.newbytorder(<byteorder>)) | |
a.nonzero() returns a tuple of arrays Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension. | |
prod(a,
axis,
dtype)
| |
ptp(a,
axis)
| |
a.put(indices, values, mode) sets a.flat[n] = values[n] for each n in indices. | |
a.ravel([fortran]) return a 1-d array (copy only if needed) | |
copy elements of a, repeats times. | |
Return a new array from this one. | |
Change array shape. | |
Rounds to 'decimals' places. | |
Find the indices into a sorted array such that if the corresponding keys in v were inserted before the indices the order of a would be preserved. | |
places val into field of the given array defined by the data type and offset. | |
setflags(a,
write,
align,
uic)
| |
Perform an inplace sort along the given axis using the algorithm specified by the kind keyword. | |
m.squeeze() eliminate all length-1 dimensions | |
Returns the standard deviation of the array elements, a measure of the spread of a distribution. | |
Sum the array over the given axis. | |
swapaxes(a,
axis1,
axis2)
Return new view with axes swapped. | |
The new array is formed from the elements of a indexed by indices along the given axis. | |
Write the data to a file. | |
Copy the data portion of the array to a hierarchical python list and return that list. | |
order -- order of the data item in the copy {"C","F","A"} (default "C") | |
return the sum along the offset diagonal of the array's indicated axis1 and axis2. | |
a.transpose(*axes) Returns a view of 'a' with axes transposed. | |
Returns the variance of the array elements, a measure of the spread of a distribution. | |
a.view(<type>) -> new view of array with same data. |
Class Variable Summary | |
---|---|
getset_descriptor |
__array_finalize__ = <attribute '__array_finalize__' of ...
|
getset_descriptor |
__array_interface__ = <attribute '__array_interface__' o...
|
getset_descriptor |
__array_priority__ = <attribute '__array_priority__' of ...
|
getset_descriptor |
__array_struct__ = <attribute '__array_struct__' of 'num...
|
getset_descriptor |
base = <attribute 'base' of 'numpy.ndarray' objects>
|
getset_descriptor |
ctypes = <attribute 'ctypes' of 'numpy.ndarray' objects>
|
getset_descriptor |
data = <attribute 'data' of 'numpy.ndarray' objects>
|
getset_descriptor |
dtype = <attribute 'dtype' of 'numpy.ndarray' objects>
|
getset_descriptor |
flags = <attribute 'flags' of 'numpy.ndarray' objects>
|
getset_descriptor |
flat = <attribute 'flat' of 'numpy.ndarray' objects>
|
getset_descriptor |
imag = <attribute 'imag' of 'numpy.ndarray' objects>
|
getset_descriptor |
itemsize = <attribute 'itemsize' of 'numpy.ndarray' obje...
|
getset_descriptor |
nbytes = <attribute 'nbytes' of 'numpy.ndarray' objects>
|
getset_descriptor |
ndim = <attribute 'ndim' of 'numpy.ndarray' objects>
|
getset_descriptor |
real = <attribute 'real' of 'numpy.ndarray' objects>
|
getset_descriptor |
shape = <attribute 'shape' of 'numpy.ndarray' objects>
|
getset_descriptor |
size = <attribute 'size' of 'numpy.ndarray' objects>
|
getset_descriptor |
strides = <attribute 'strides' of 'numpy.ndarray' object...
|
getset_descriptor |
T = <attribute 'T' of 'numpy.ndarray' objects>
|
Method Details |
---|
__array__(...)a.__array__(|dtype) -> reference if type unchanged, copy otherwise. Returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array. |
__copy__(...)a.__copy__(|order) -> copy, possibly with different order. Return a copy of the array.
|
__deepcopy__(a)Used if copy.deepcopy is called on an array.
|
__delslice__(x,
i,
j)
|
__getslice__(x,
i,
j)
|
__index__(...)x[y:z] <==> x[y.__index__():z.__index__()] |
__reduce__(a)For pickling.
|
__setslice__(x,
i,
j,
y)
|
__setstate__(a, version, shape, typecode, isfortran, rawdata)For unpickling.
|
argsort(a, axis=-1, kind='quicksort', order=None)Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as 'a' that index data along the given axis in sorted order. :Parameters: axis : integer Axis to be indirectly sorted. None indicates that the flattened array should be used. Default is -1. kind : string Sorting algorithm to use. Possible values are 'quicksort', 'mergesort', or 'heapsort'. Default is 'quicksort'. order : list type or None When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified. :Returns: indices : integer array Array of indices that sort 'a' along the specified axis. :SeeAlso: - lexsort : indirect stable sort with multiple keys - sort : inplace sort :Notes: ------ The various sorts are characterized by average speed, worst case performance, need for work space, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The three available algorithms have the following properties: |------------------------------------------------------| | kind | speed | worst case | work space | stable| |------------------------------------------------------| |'quicksort'| 1 | O(n^2) | 0 | no | |'mergesort'| 2 | O(n*log(n)) | ~n/2 | yes | |'heapsort' | 3 | O(n*log(n)) | 0 | no | |------------------------------------------------------| All the sort algorithms make temporary copies of the data when the sort is not along the last axis. Consequently, sorts along the last axis are faster and use less space than sorts along other axis.
|
astype(a, t)Cast array m to type t. t can be either a string representing a typecode, or a python type object of type int, float, or complex.
|
byteswap(a, False)Swap the bytes in the array. Swap the bytes in the array. Return the byteswapped array. If the first argument is True, byteswap in-place and return a reference to self.
|
choose(a, b0, b1, bn, out=None, mode='raise', ...)Return an array that merges the b_i arrays together using 'a' as the index The b_i arrays and 'a' must all be broadcastable to the same shape. The output at a particular position is the input array b_i at that position depending on the value of 'a' at that position. Therefore, 'a' must be an integer array with entries from 0 to n+1.; |
copy(...)a.copy(|order) -> copy, possibly with different order. Return a copy of the array.
|
diagonal(a, offset=0, axis1=0, axis2=1)If a is 2-d, return the diagonal of self with the given offset, i.e., the collection of elements of the form a[i,i+offset]. If a is n-d with n > 2, then the axes specified by axis1 and axis2 are used to determine the 2-d subarray whose diagonal is returned. The shape of the resulting array can be determined by removing axis1 and axis2 and appending an index to the right equal to the size of the resulting diagonals. Examples>>> a = arange(4).reshape(2,2) >>> a array([[0, 1], [2, 3]]) >>> a.diagonal() array([0, 3]) >>> a.diagonal(1) array([1]) >>> a = arange(8).reshape(2,2,2) >>> a array([[[0, 1], [2, 3]],
>>> a.diagonal(0,-2,-1) array([[0, 3], [4, 7]])
|
dump(...)a.dump(file) Dump a pickle of the array to the specified file. The array can be read back with pickle.load or numpy.load
|
dumps(...)a.dumps() returns the pickle of the array as a string. pickle.loads or numpy.loads will convert the string back to an array. |
fill(a, value)Fill the array with the scalar value.
|
flatten(...)a.flatten([fortran]) return a 1-d array (always copy) |
getfield(a, dtype, offset)Returns a field of the given array as a certain type. A field is a view of the array data with each itemsize determined by the given type and the offset into the current array.
|
item(a)Copy the first element of array to a standard Python scalar and return it. The array must be of size one.
|
mean(a, axis=None, dtype=None, out=None)Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. NotesThe mean is the sum of the elements along the axis divided by the number of elements.
|
newbyteorder(...)a.newbyteorder(<byteorder>) is equivalent to a.view(a.dtype.newbytorder(<byteorder>)) |
nonzero(...)a.nonzero() returns a tuple of arrays Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with a[a.nonzero()]. To group the indices by element, rather than dimension, use transpose(a.nonzero()) instead. The result of this is always a 2d array, with a row for each non-zero element.; |
put(...)a.put(indices, values, mode) sets a.flat[n] = values[n] for each n in indices. If values is shorter than indices then it will repeat. |
ravel(...)a.ravel([fortran]) return a 1-d array (copy only if needed) |
repeat(a, repeats=, axis=none)copy elements of a, repeats times. the repeats argument must be a sequence of length a.shape[axis] or a scalar. |
reshape(a, d1, d2, dn, order='c', ...)Return a new array from this one. The new array must have the same number of elements as self. Also always returns a view or raises a ValueError if that is impossible. |
resize(a, new_shape, refcheck=True, order=False)Change array shape. Change size and shape of self inplace. Array must own its own memory and not be referenced by other arrays. Returns None.
|
round(a, decimals=0, out=None)Rounds to 'decimals' places.
Round to the specified number of decimals. When 'decimals' is negative it specifies the number of positions to the left of the decimal point. The real and imaginary parts of complex numbers are rounded separately. Nothing is done if the array is not of float type and 'decimals' is >= 0. The keyword 'out' may be used to specify a different array to hold the result rather than the default 'a'. If the type of the array specified by 'out' differs from that of 'a', the result is cast to the new type, otherwise the original type is kept. Floats round to floats by default. Numpy rounds to even. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due to the inexact representation of decimal fractions in IEEE floating point and the errors introduced in scaling the numbers when 'decimals' is something other than 0.
|
searchsorted(a, v, side='left')Find the indices into a sorted array such that if the corresponding keys in v were inserted before the indices the order of a would be preserved. If side='left', then the first such index is returned. If side='right', then the last such index is returned. If there is no such index because the key is out of bounds, then the length of a is returned, i.e., the key would need to be appended. The returned index array has the same shape as v. The array a must be 1-d and is assumed to be sorted in ascending order. Searchsorted uses binary search to find the required insertion points.
|
setfield(m, value, dtype, offset)places val into field of the given array defined by the data type and offset.
|
sort(a, axis=-1, kind='quicksort', order=None)Perform an inplace sort along the given axis using the algorithm specified by the kind keyword. :Parameters: axis : integer Axis to be sorted along. None indicates that the flattened array should be used. Default is -1. kind : string Sorting algorithm to use. Possible values are 'quicksort', 'mergesort', or 'heapsort'. Default is 'quicksort'. order : list type or None When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified. :Returns: None :SeeAlso: - argsort : indirect sort - lexsort : indirect stable sort on multiple keys - searchsorted : find keys in sorted array :Notes: ------ The various sorts are characterized by average speed, worst case performance, need for work space, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The three available algorithms have the following properties: |------------------------------------------------------| | kind | speed | worst case | work space | stable| |------------------------------------------------------| |'quicksort'| 1 | O(n^2) | 0 | no | |'mergesort'| 2 | O(n*log(n)) | ~n/2 | yes | |'heapsort' | 3 | O(n*log(n)) | 0 | no | |------------------------------------------------------| All the sort algorithms make temporary copies of the data when the sort is not along the last axis. Consequently, sorts along the last axis are faster and use less space than sorts along other axis.
|
squeeze(...)m.squeeze() eliminate all length-1 dimensions |
std(a, axis=None, dtype=None, out=None)Returns the standard deviation of the array elements, a measure of the spread of a distribution. The standard deviation is computed for the flattened array by default, otherwise over the specified axis. NotesThe standard deviation is the square root of the average of the squared deviations from the mean, i.e. var = sqrt(mean((x - x.mean())**2)). The computed standard deviation is biased, i.e., the mean is computed by dividing by the number of elements, N, rather than by N-1.
|
sum(a, axis=None, dtype=None)Sum the array over the given axis. If the axis is None, sum over all dimensions of the array. The optional dtype argument is the data type for the returned value and intermediate calculations. The default is to upcast (promote) smaller integer types to the platform-dependent int. For example, on 32-bit platforms: a.dtype default sum dtype --------------------------------------------------- bool, int8, int16, int32 int32 Warning: The arithmetic is modular and no error is raised on overflow. Examples: >>> array([0.5, 1.5]).sum() 2.0 >>> array([0.5, 1.5]).sum(dtype=int32) 1 >>> array([[0, 1], [0, 5]]).sum(axis=0) array([0, 6]) >>> array([[0, 1], [0, 5]]).sum(axis=1) array([1, 5]) >>> ones(128, dtype=int8).sum(dtype=int8) # overflow! -128
|
take(a, indices, axis=None, out=None, mode='raise')The new array is formed from the elements of a indexed by indices along the given axis.
|
tofile(a, fid, sep="", format="%s")Write the data to a file.
A convenience function for quick storage of array data. Information on endianess and precision is lost, so this method is not a good choice for files intended to archive data or transport data between machines with different endianess. Some of these problems can be overcome by outputting the data as text files at the expense of speed and file size. If 'sep' is empty this method is equivalent to file.write(a.tostring()). If 'sep' is not empty each data item is converted to the nearest Python type and formatted using "format"%item. The resulting strings are written to the file separated by the contents of 'sep'. The data is always written in "C" (row major) order independent of the order of 'a'. The data produced by this method can be recovered by using the function fromfile().
|
tolist(a)Copy the data portion of the array to a hierarchical python list and return that list. Data items are converted to the nearest compatible Python type.
|
tostring(a, order='C')
Construct a Python string containing the raw bytes in the array. The order of the data in arrays with ndim > 1 is specified by the 'order' keyword and this keyword overrides the order of the array. The choices are: "C" -- C order (row major) "Fortran" -- Fortran order (column major) "Any" -- Current order of array. None -- Same as "Any"
|
trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)return the sum along the offset diagonal of the array's indicated axis1 and axis2. |
transpose(...)a.transpose(*axes) Returns a view of 'a' with axes transposed. If no axes are given, or None is passed, switches the order of the axes. For a 2-d array, this is the usual matrix transpose. If axes are given, they describe how the axes are permuted. Example: >>> a = array([[1,2],[3,4]]) >>> a array([[1, 2], [3, 4]]) >>> a.transpose() array([[1, 3], [2, 4]]) >>> a.transpose((1,0)) array([[1, 3], [2, 4]]) >>> a.transpose(1,0) array([[1, 3], [2, 4]]) |
var(a, axis=None, dtype=None, out=None)Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. NotesThe variance is the average of the squared deviations from the mean, i.e. var = mean((x - x.mean())**2). The computed variance is biased, i.e., the mean is computed by dividing by the number of elements, N, rather than by N-1.
|
view(...)a.view(<type>) -> new view of array with same data. Type can be either a new sub-type object or a data-descriptor object |
Class Variable Details |
---|
__array_finalize__
|
__array_interface__
|
__array_priority__
|
__array_struct__
|
base
|
ctypes
|
data
|
dtype
|
flags
|
flat
|
imag
|
itemsize
|
nbytes
|
ndim
|
real
|
shape
|
size
|
strides
|
T
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1.20050511.rpd on Mon Feb 16 12:51:22 2009 | http://epydoc.sf.net |