Package numpy :: Class ndarray
[frames | no frames]

Type ndarray

object --+
         |
        ndarray

Known Subclasses:
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...
  __array__(...)
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...
  __copy__(...)
a.__copy__(|order) -> copy, possibly with different order.
  __deepcopy__(a)
Used if copy.deepcopy is called on an array.
  __delitem__(x, y)
Return del x[y]...
  __delslice__(x, i, j)
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]...
  __getslice__(x, i, j)
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...
  __index__(...)
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)...
  __reduce__(a)
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...
  __setslice__(x, i, j, y)
Use of negative indices is not supported.
  __setstate__(a, version, shape, typecode, isfortran, rawdata)
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)
  argsort(a, axis, kind, order)
Perform an indirect sort along the given axis using the algorithm specified by the kind keyword.
  astype(a, t)
Cast array m to type t.
  byteswap(a, False)
Swap the bytes in the array.
  choose(a, b0, b1, bn, out, mode, ...)
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)
  copy(...)
a.copy(|order) -> copy, possibly with different order.
  cumprod(a, axis, dtype)
  cumsum(a, axis, dtype, out)
  diagonal(a, offset, axis1, axis2)
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].
  dump(...)
a.dump(file) Dump a pickle of the array to the specified file.
  dumps(...)
a.dumps() returns the pickle of the array as a string.
  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.
  item(a)
Copy the first element of array to a standard Python scalar and return it.
  itemset(...)
  max(a, axis)
  mean(a, axis, dtype, out)
Returns the average of the array elements.
  min(a, axis)
  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.
  prod(a, axis, dtype)
  ptp(a, axis)
  put(...)
a.put(indices, values, mode) sets a.flat[n] = values[n] for each n in indices.
  ravel(...)
a.ravel([fortran]) return a 1-d array (copy only if needed)
  repeat(a, repeats, axis)
copy elements of a, repeats times.
  reshape(a, d1, d2, dn, order, ...)
Return a new array from this one.
  resize(a, new_shape, refcheck, order)
Change array shape.
  round(a, decimals, out)
Rounds to 'decimals' places.
  searchsorted(a, v, side)
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.
  setfield(m, value, dtype, offset)
places val into field of the given array defined by the data type and offset.
  setflags(a, write, align, uic)
  sort(a, axis, kind, order)
Perform an inplace sort along the given axis using the algorithm specified by the kind keyword.
  squeeze(...)
m.squeeze() eliminate all length-1 dimensions
  std(a, axis, dtype, out)
Returns the standard deviation of the array elements, a measure of the spread of a distribution.
  sum(a, axis, dtype)
Sum the array over the given axis.
  swapaxes(a, axis1, axis2)
Return new view with axes swapped.
  take(a, indices, axis, out, mode)
The new array is formed from the elements of a indexed by indices along the given axis.
  tofile(a, fid, sep, format)
Write the data to a file.
  tolist(a)
Copy the data portion of the array to a hierarchical python list and return that list.
  tostring(a, order)
order -- order of the data item in the copy {"C","F","A"} (default "C")
  trace(a, offset, axis1, axis2, dtype, out)
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.
  var(a, axis, dtype, out)
Returns the variance of the array elements, a measure of the spread of a distribution.
  view(...)
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.

Argument:
order -- Order of returned copy (default 'C')
If order is 'C' (False) then the result is contiguous (default). If order is 'Fortran' (True) then the result has fortran order. If order is 'Any' (None) then the result has fortran order only if m is already in fortran order.;

__deepcopy__(a)

Used if copy.deepcopy is called on an array.

Returns:
Deep copy of array

__delslice__(x, i, j)
(Slice deletion operator)

Use of negative indices is not supported.

Returns:
del x[i:j]

__getslice__(x, i, j)
(Slicling operator)

Use of negative indices is not supported.

Returns:
x[i:j]

__index__(...)

x[y:z] <==> x[y.__index__():z.__index__()]

__reduce__(a)

For pickling.

Overrides:
__builtin__.object.__reduce__

__setslice__(x, i, j, y)
(Slice assignment operator)

Use of negative indices is not supported.

Returns:
x[i:j]=y

__setstate__(a, version, shape, typecode, isfortran, rawdata)

For unpickling.

Arguments:
version -- optional pickle version. If omitted defaults to 0. shape -- a tuple giving the shape typecode -- a typecode isFortran -- a bool stating if Fortran or no rawdata -- a binary string with the data (or a list if Object array)

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.
Returns:
indices

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.

Returns:
Copy of array cast to type t

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.

Returns:
View or copy

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.

Argument:
order -- Order of returned copy (default 'C')
If order is 'C' (False) then the result is contiguous (default). If order is 'Fortran' (True) then the result has fortran order. If order is 'Any' (None) then the result has fortran order only if m is already in fortran order.;

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]],
[[4, 5],
[6, 7]]])
>>> a.diagonal(0,-2,-1)
array([[0, 3],
       [4, 7]])
Returns:
array_of_diagonals : same type as original array
If a is 2-d, then a 1-d array containing the diagonal is returned. If a is n-d, n > 2, then an array of diagonals is returned.

See Also:

  • diag : matlab workalike for 1-d and 2-d arrays.
  • diagflat : creates diagonal arrays
  • trace : sum along diagonals

Parameters:

offset : integer
Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to main diagonal.
axis1 : integer
Axis to be used as the first axis of the 2-d subarrays from which the diagonals should be taken. Defaults to first index.
axis2 : integer
Axis to be used as the second axis of the 2-d subarrays from which the diagonals should be taken. Defaults to second index.

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

Arguments:
file -- string naming the dump file.

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.

Returns:
None

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.

Returns:
field of array as given type

item(a)

Copy the first element of array to a standard Python scalar and return it. The array must be of size one.

Returns:
copy of first array item as Python scalar

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.

Notes

The mean is the sum of the elements along the axis divided by the number of elements.
Returns:
mean : The return type varies, see above.
A new array holding the result is returned unless out is specified, in which case a reference to out is returned.

See Also:

  • var : variance
  • std : standard deviation

Parameters:

axis : integer
Axis along which the means are computed. The default is to compute the standard deviation of the flattened array.
dtype : type
Type to use in computing the means. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type.
out : ndarray
Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary.

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.

Returns:
None

round(a, decimals=0, out=None)

Rounds to 'decimals' places.

Keyword arguments:
decimals -- number of decimals to round to (default 0). May be negative. out -- existing array to use for output (default a).
Return:
Reference to out, where None specifies the original array a.

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.

Returns:
out (a)

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.
Returns:
indices : integer array
The returned array has the same shape as v.

See Also:

  • sort
  • histogram

Parameters:

v : array or list type
Array of keys to be searched for in a.
side : string
Possible values are : 'left', 'right'. Default is 'left'. Return the first or last index where the key could be inserted.

setfield(m, value, dtype, offset)

places val into field of the given array defined by the data type and offset.

Returns:
None

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.
Returns:
None

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.

Notes

The 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.
Returns:
standard deviation : The return type varies, see above.
A new array holding the result is returned unless out is specified, in which case a reference to out is returned.

See Also:

  • var : variance
  • mean : average

Parameters:

axis : integer
Axis along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
dtype : type
Type to use in computing the standard deviation. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type.
out : ndarray
Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary.

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
Returns:
Sum of array over given axis

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.

Returns:
new array

tofile(a, fid, sep="", format="%s")

Write the data to a file.

Required arguments:
file -- an open file object or a string containing a filename
Keyword arguments:
sep -- separator for text output. Write binary if empty (default "") format -- format string for text file output (default "%s")

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().

Returns:
None

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.

Returns:
Array as hierarchical list

tostring(a, order='C')

Keyword arguments:
order -- order of the data item in the copy {"C","F","A"} (default "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"
Returns:
raw copy of array data as a Python string

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.

Notes

The 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.
Returns:
variance : The return type varies, see above.
A new array holding the result is returned unless out is specified, in which case a reference to out is returned.

See Also:

  • std : standard deviation
  • mean: average

Parameters:

axis : integer
Axis along which the variance is computed. The default is to compute the variance of the flattened array.
dtype : type
Type to use in computing the variance. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type.
out : ndarray
Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary.

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__

Type:
getset_descriptor
Value:
<attribute '__array_finalize__' of 'numpy.ndarray' objects>            

__array_interface__

Type:
getset_descriptor
Value:
<attribute '__array_interface__' of 'numpy.ndarray' objects>           

__array_priority__

Type:
getset_descriptor
Value:
<attribute '__array_priority__' of 'numpy.ndarray' objects>            

__array_struct__

Type:
getset_descriptor
Value:
<attribute '__array_struct__' of 'numpy.ndarray' objects>              

base

Type:
getset_descriptor
Value:
<attribute 'base' of 'numpy.ndarray' objects>                          

ctypes

Type:
getset_descriptor
Value:
<attribute 'ctypes' of 'numpy.ndarray' objects>                        

data

Type:
getset_descriptor
Value:
<attribute 'data' of 'numpy.ndarray' objects>                          

dtype

Type:
getset_descriptor
Value:
<attribute 'dtype' of 'numpy.ndarray' objects>                         

flags

Type:
getset_descriptor
Value:
<attribute 'flags' of 'numpy.ndarray' objects>                         

flat

Type:
getset_descriptor
Value:
<attribute 'flat' of 'numpy.ndarray' objects>                          

imag

Type:
getset_descriptor
Value:
<attribute 'imag' of 'numpy.ndarray' objects>                          

itemsize

Type:
getset_descriptor
Value:
<attribute 'itemsize' of 'numpy.ndarray' objects>                      

nbytes

Type:
getset_descriptor
Value:
<attribute 'nbytes' of 'numpy.ndarray' objects>                        

ndim

Type:
getset_descriptor
Value:
<attribute 'ndim' of 'numpy.ndarray' objects>                          

real

Type:
getset_descriptor
Value:
<attribute 'real' of 'numpy.ndarray' objects>                          

shape

Type:
getset_descriptor
Value:
<attribute 'shape' of 'numpy.ndarray' objects>                         

size

Type:
getset_descriptor
Value:
<attribute 'size' of 'numpy.ndarray' objects>                          

strides

Type:
getset_descriptor
Value:
<attribute 'strides' of 'numpy.ndarray' objects>                       

T

Type:
getset_descriptor
Value:
<attribute 'T' of 'numpy.ndarray' objects>                             

Generated by Epydoc 2.1.20050511.rpd on Mon Feb 16 12:51:22 2009 http://epydoc.sf.net