NumPy is a collection of extension modules to provide high-performance multidimensional numeric arrays to the Python programming language.

The following functions are used to produce a new array.

Creates an array object from the given **sequence** determining the shape from the structure of the nested python sequence, and the type as the minimal type that will "fit" all the items in the sequence, or from the desired **typecode** if given.

The **typecode** should be specfied as a type followed by bits of precision. The following constants are available on most systems: Int8, Int16, Int32, Int64 (on 64-bit processors), Float32, Float64, Complex32, Complex64. You can also use the constants Int, Float, Complex to get the largest version of the given type available on your system. To get an array of heterogeneous python objects, use the code PyObject.

If the copy flag is set, this function will always return a new array with data copied from the source sequence. If it is set to zero, then no copy will be made if the source sequence is already an array object of the appropriate typecode, but instead a new object will be returned which refers to the same memory block as the source sequence.

Will create an array of **shape** and given **typecode** filled with zeros. For both this function and for **ones**, **shape** is allowed to be either a tuple, or a single integer corresponding to a 1d array shape.

Will create an array of **shape** and given **typecode** filled with ones.

The same as array(range(**start**, **stop**, **step**), **typecode**), but much more efficient

Will return the array formed by the binary data given in **string** of the specified **typecode**. This is mainly used for reading binary data to and from files, it can also be used to exchange binary data with other modules that use python strings as storage (i.e. PIL).

Note: this function treats the **string **as a binary array of data. It is not designed for parsing a string of ASCII numbers to produce an array.

Will return a **n** x **n** identity matrix

Will return an array of the indices for the given shaped array. The outermost dimension specifies which index, and the other dimensions match those given in shape.

Will return a new array of the given shape where function is called on the indices of the array. function must only use numerical operations and ufuncs on its arguments. This restriction should be relaxed in the future.

This is equivalent to arrayrange

This is not necessarily a constructor. If its argument is an array of the right type, you get that argument back. If it is anything else, it will be passed to array(a, typecode). This is a handy way in a function of making sure you have an array without doing any unnecessary copying.

Selects the elements of **a** along the **axis** indicated by **indices**. **indices** is an array of integers, where negative values are considered to be indexing from the end of the axis (just like normal python negative indices).

Change the shape of **a** to be given by the new **shape**. **shape** is a tuple of the dimensions of the array. One entry in shape is allowed to be -1, and this dimension will be set to whatever value will make the new shape the same total size as the old one. The size of the new array must be exactly equal to the size of the old one. Use resize for changing the size and shape of an array.

Exactly like reshape, except that the new size of a can be anything. This is a less efficient operation that reshape, and can produce strange results if you're not careful.

Will swap the axes of **a** so that their new order is that given in **axes**. Negative axes are allowed and are taken as indexing from the end of the list of axes. If axes is not specified, it will be set to range(len(a.shape)).reverse().

Each element in **a** is repeated as often as indicated be the corresponding elements in **repeats**. The length of the result along the given axis is equal to the sum of the elements in **repeats**. The shape of the result along all other axes is unchanged.

**a** is an array of integers between 0 and n. The resulting array will have the same shape as **a**, with element selected from **b _{0}**,...,

The arrays will be concatenated along the given axis. All arrays must have the same shape along every axis except for the one given. To concatenate arrays along a newly created axis, you can use array((a_{0},...,a_{n})) so long as all arrays have the same shape.

Returns the entries along the **k**^{th} diagonal of **a** (**k** is an offset from the main diagonal). This is designed for 2d arrays. For larger arrays, it will return the diagonal of each 2d subarray.

Returns **a** as a 1d array. Equivalent to reshape(**a**, (-1,)) .

Returns the indices of the elements in **a** that are nonzero. Only makes sense for 1d arrays.

The result is shaped like **condition** and has elements of **true** and **false** where condition is respectively true or false.

Returns those elements of **a** corresponding to those elements of **condition** that are nonzero. **Condition** must be the same size as the given **axis** of **a**. The shape of the result along **axis** will be equal to the number of nonzero elements in **condition**. The shape of the result along all other axes will be the same as **a**.

Returns the sum of the elements in **a** along the **k**^{th} diagonal.

Will sort the elements of **a** along the given **axis**.

Will return the indices of the elements of a needed to produce sort(**a**). ie. take(**a**, argsort(**a**)) == sort(**a**).

**a** must be sorted in ascending order and 1d. This will return the indices of the positions in a where the corresponding values would fit.

Returns the arguments of the maximum/minimum values of **a** along the given **axis**. The returned array will have one less dimension than **a**.

There are very few methods provided for array objects, most of the functionality is instead available as functions. This is done in order to allow these functions to work on arbitrary python sequences. i.e. transpose([[1,2],[3,4]]) works just fine, but [[1,2],[3,4]].transpose() couldn't possibly work. This approach also allows uniformity in interface between functions defined in the base system in C, in python and functions defined on array objects in extensions. All of these methods depend critically on the implementation details of array objects.

Will return a new array with all the elements of **a** cast to **typecode**. Warning: this cast is the straight C cast from one type to another and contains no range checks at all! You can always add you're own range checks if you're concerned.

The size in bytes of a single element in **a**.

Returns a new array containg the same data as **a**, except it**s** byteswapped. This is useful for exchanging binary data between machines with different byte orders.

Returns the character used to indicate the type of the elements in **a**.

True if **a** is a contiguous array. array(a) or copy.copy(a) are guaranteed to produce contiguous arrays if needed.

Returns the binary data contained in **a** as a python string. If **a** is discontiguous, this data will still be faked to look as if it came from a contiguous array.

Returns **a** as a hierarchical python list. This is useful for passing to functions that explicitly want python lists.

Array objects have four attributes, only two of which are likely to be of general usefulness.

a.shape

Returns a tuple of the lengths of a along each of its dimensions. Use len(a.shape) to get the number of dimensions in **a**. This attribute is settable, and can be used to change the shape of an array. It can only be set to a new shape that will have exactly the same number of elements as the original shape. See the function resize if this is not the desired behavior.

a.flat

This attribute is only available for contiguous arrays. It will return a one-dimensional array of the elements in a.

a.real

This returns the real part of an array. For non-complex arrays, this is exactly equal to the array itself.

a.imaginary

This returns the imaginary part of a complex array, and raises an exception for a real array.

These are the objects contained in umath (and fast_umath). They are callable objects and can be used just like the equivalent functions, in addition they have methods to allow reductions, accumulations, and outer products.

Hopefully these names are all self explanatory!

All of the previously given functions have the following methods

Works just like reduce(**ufunc**, **a**, [**ufunc**'s identity element]) except you get to choose the **axis** to perform the reduction along. Note that if the length of **a **long **axis **is 0, then the appropriate identity element for the **ufunc** will be returned.

This is the same as reduce, except that all the intermediate results are kept along the way.

This will take the outer product of **a** and **b**. The new results shape will be the same as a.shape+b.shape (where plus means concatenate, not add!)

This is a weird function, and most people should just ignore it. It will reduce a to each of the given indices so that a**s** new size along the given axis will be the same as the length of indices.

Will return the dot product of a and b. This is equivalent to matrix multiply for 2d arrays (without the transpose). Somebody who does more linear algebra really needs to do this function right some day!

Will return the convolution of a and b. This function is implemented in the standard manner, not using FFT's. It is intended for convolving a large array with a small one. I personally use it for convolving with a gaussian to smooth waveforms. The mode can be set to either 0, 1, or 2.

- 0 - the length of the resulting array will be len(a)-len(b)+1
- 1 - the length of the resulting array will be len(a)
- 2 - the length of the resulting array will be len(a)+len(b)-1

For modes 1 and 2, the arrays are zero padded on the left and right sides to provide for missing elements.

Will clip the values in **a** to lie between **max** and **min**.

The underlying code for these functions is an f2c translated and modified version of the FFTPACK routines.

Will return the **n** point discrete Fourier transform of **a**. **n** defaults to the length of **a**. This is most efficient for **n** a power of two. If **n** is larger than **a**, then **a** will be zero-padded to make up the difference. If **n** is smaller than **a**, then **a** will be aliased to reduce its size. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's.

Will return the **n** point inverse discrete Fourier transform of **a**. **n** defaults to the length of **a**. This is most efficient for **n** a power of two. If **n** is larger than **a**, then **a** will be zero-padded to make up the difference. If **n** is smaller than **a**, then **a** will be aliased to reduce its size. This also stores a cache of working memory for different sizes of fft's, so you could theoretically run into memory problems if you call this too many times with too many different n's.

Will return the **n** point discrete Fourier transform of the real valued array **a**. **n** defaults to the length of **a**. This is most efficient for **n** a power of two. The returned array will be one half of the symmetric complex transform of the real array.

The 2d fft of **a**.

The 2d fft of the real valued array **a**.

The underlying code for these routines is from ranlib

Set the seed of the random number generator from two integers. If both are zero, then seed will come from the system clock.

Returns the two integers that are the generators current seed.

Returns an array of random numbers uniformly distributed between 0 and 1 of the given shape. Returns a scalar if shape is empty (as in the default).

The random numbers are uniformly distributed between minimum and maximum

An array of integers between minimum and maximum, not including the value of maximum (as in range).

A random resorting of the values in arrayrange(n)

The underlying code for these routines comes from LAPACK

Returns the inverse of the matrix a. matrixmultiply(a, inverse(a)) == identity(len(a))

Just get the eigenvalues for a

eigenvectors(a) returns u,v where u is the eigenvalues and

v is a matrix of eigenvectors with vector v[i] corresponds to

eigenvalue u[i]. Satisfies the equation matrixmultiply(a, v[i]) = u[i]*v[i]

Returns the determinate of the square matrix a

solveLinearLeastSquares(a,b) returns x,resids,rank,s

where x minimizes 2-norm(|b - Ax|)

resids is the sum square residuals

rank is the rank of A

s is an rank of the singual values of A in desending order

If b is a matrix then x is also a matrix with corresponding columns.

If the rank of A is less than the number of columns of A or greater than

the numer of rows, then residuals will be returned as an empty array

otherwise resids = sum((b-dot(A,x)**2).

Singular values less than s[0]*rcond are treated as zero.