537 lines (534 with data), 49.5 kB
@header@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="matplotlib.html"><font color="#ffffff">matplotlib</font></a>.mlab</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.4/site-packages/matplotlib/mlab.py">/usr/lib/python2.4/site-packages/matplotlib/mlab.py</a></font></td></tr></table>
<p><tt>Numerical python functions written for compatability with matlab(TM)<br>
commands with the same names. <br>
<br>
Matlab(TM) compatible functions:<br>
<br>
* cohere - Coherence (normalized cross spectral density)<br>
<br>
* conv - convolution<br>
<br>
* corrcoef - The matrix of correlation coefficients<br>
<br>
* csd - Cross spectral density uing Welch's average periodogram<br>
<br>
* detrend -- Remove the mean or best fit line from an array<br>
<br>
* find - Return the indices where some condition is true<br>
<br>
* linspace -- Linear spaced array from min to max<br>
<br>
* hist -- Histogram<br>
<br>
* polyfit - least squares best polynomial fit of x to y<br>
<br>
* polyval - evaluate a vector for a vector of polynomial coeffs<br>
<br>
* prctile - find the percentiles of a sequence<br>
<br>
* prepca - Principal Component's Analysis<br>
<br>
* psd - Power spectral density uing Welch's average periodogram<br>
<br>
* rk4 - A 4th order runge kutta integrator for 1D or ND systems<br>
<br>
* vander - the Vandermonde matrix<br>
<br>
* trapz - trapeziodal integration<br>
<br>
Functions that don't exist in matlab(TM), but are useful anyway:<br>
<br>
* cohere_pairs - Coherence over all pairs. This is not a matlab<br>
function, but we compute coherence a lot in my lab, and we<br>
compute it for alot of pairs. This function is optimized to do<br>
this efficiently by caching the direct FFTs.<br>
<br>
Credits:<br>
<br>
Unless otherwise noted, these functions were written by<br>
Author: John D. Hunter <jdhunter@ace.bsd.uchicago.edu><br>
<br>
Some others are from the Numeric documentation, or imported from<br>
MLab or other Numeric packages</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="matplotlib.numerix.linear_algebra.html">matplotlib.numerix.linear_algebra</a><br>
<a href="math.html">math</a><br>
</td><td width="25%" valign=top><a href="matplotlib.numerix.html">matplotlib.numerix</a><br>
<a href="operator.html">operator</a><br>
</td><td width="25%" valign=top><a href="random.html">random</a><br>
<a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-amap"><strong>amap</strong></a>(fn, *args)</dt><dd><tt><a href="#-amap">amap</a>(function, sequence[, sequence, ...]) -> array.<br>
<br>
Works like map(), but it returns an array. This is just a convenient<br>
shorthand for Numeric.<a href="#-array">array</a>(map(...))</tt></dd></dl>
<dl><dt><a name="-approx_real"><strong>approx_real</strong></a>(x)</dt><dd><tt><a href="#-approx_real">approx_real</a>(x) : returns x.real if |x.imag| < |x.real| * _eps_approx.<br>
This function is needed by sqrtm and allows further functions.</tt></dd></dl>
<dl><dt><a name="-arange"><strong>arange</strong></a>(...)</dt><dd><tt><a href="#-arange">arange</a>(start, stop=None, step=1, typecode=None)<br>
<br>
Just like range() except it returns an array whose type can be<br>
specified by the keyword argument typecode.</tt></dd></dl>
<dl><dt><a name="-array"><strong>array</strong></a>(...)</dt><dd><tt><a href="#-array">array</a>(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode. If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence. If copy is zero and sequence is already an array, a reference will be returned. If savespace is nonzero, the new array will maintain its precision in operations.</tt></dd></dl>
<dl><dt><a name="-base_repr"><strong>base_repr</strong></a>(number, base<font color="#909090">=2</font>, padding<font color="#909090">=0</font>)</dt><dd><tt>Return the representation of a number in any given base.</tt></dd></dl>
<dl><dt><a name="-binary_repr"><strong>binary_repr</strong></a>(number, max_length<font color="#909090">=1025</font>)</dt><dd><tt>Return the binary representation of the input number as a string.<br>
<br>
This is more efficient than using base_repr with base 2.<br>
<br>
Increase the value of max_length for very large numbers. Note that on<br>
32-bit machines, 2**1023 is the largest integer power of 2 which can be<br>
converted to a Python float.</tt></dd></dl>
<dl><dt><a name="-bivariate_normal"><strong>bivariate_normal</strong></a>(X, Y, sigmax<font color="#909090">=1.0</font>, sigmay<font color="#909090">=1.0</font>, mux<font color="#909090">=0.0</font>, muy<font color="#909090">=0.0</font>, sigmaxy<font color="#909090">=0.0</font>)</dt><dd><tt>Bivariate gaussan distribution for equal shape X, Y<br>
<br>
<a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html">http://mathworld.wolfram.com/BivariateNormalDistribution.html</a></tt></dd></dl>
<dl><dt><a name="-center_matrix"><strong>center_matrix</strong></a>(M, dim<font color="#909090">=0</font>)</dt><dd><tt>Return the matrix M with each row having zero mean and unit std<br>
<br>
if dim=1, center columns rather than rows</tt></dd></dl>
<dl><dt><a name="-cohere"><strong>cohere</strong></a>(x, y, NFFT<font color="#909090">=256</font>, Fs<font color="#909090">=2</font>, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_hanning></font>, noverlap<font color="#909090">=0</font>)</dt><dd><tt>cohere the coherence between x and y. Coherence is the normalized<br>
cross spectral density<br>
<br>
Cxy = |Pxy|^2/(Pxx*Pyy)<br>
<br>
The return value is (Cxy, f), where f are the frequencies of the<br>
coherence vector. See the docs for psd and csd for information<br>
about the function arguments NFFT, detrend, windowm noverlap, as<br>
well as the methods used to compute Pxy, Pxx and Pyy.<br>
<br>
Returns the tuple Cxy, freqs</tt></dd></dl>
<dl><dt><a name="-cohere_pairs"><strong>cohere_pairs</strong></a>(X, ij, NFFT<font color="#909090">=256</font>, Fs<font color="#909090">=2</font>, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_hanning></font>, noverlap<font color="#909090">=0</font>, preferSpeedOverMemory<font color="#909090">=True</font>, progressCallback<font color="#909090">=<function donothing_callback></font>, returnPxx<font color="#909090">=False</font>)</dt><dd><tt>Cxy, Phase, freqs = <a href="#-cohere_pairs">cohere_pairs</a>( X, ij, ...)<br>
<br>
Compute the coherence for all pairs in ij. X is a<br>
numSamples,numCols Numeric array. ij is a list of tuples (i,j).<br>
Each tuple is a pair of indexes into the columns of X for which<br>
you want to compute coherence. For example, if X has 64 columns,<br>
and you want to compute all nonredundant pairs, define ij as<br>
<br>
ij = []<br>
for i in range(64):<br>
for j in range(i+1,64):<br>
ij.append( (i,j) )<br>
<br>
The other function arguments, except for 'preferSpeedOverMemory'<br>
(see below), are explained in the help string of 'psd'.<br>
<br>
Return value is a tuple (Cxy, Phase, freqs).<br>
<br>
Cxy -- a dictionary of (i,j) tuples -> coherence vector for that<br>
pair. Ie, Cxy[(i,j) = <a href="#-cohere">cohere</a>(X[:,i], X[:,j]). Number of<br>
dictionary keys is len(ij)<br>
<br>
Phase -- a dictionary of phases of the cross spectral density at<br>
each frequency for each pair. keys are (i,j).<br>
<br>
freqs -- a vector of frequencies, equal in length to either the<br>
coherence or phase vectors for any i,j key. Eg, to make a coherence<br>
Bode plot:<br>
<br>
subplot(211)<br>
plot( freqs, Cxy[(12,19)])<br>
subplot(212)<br>
plot( freqs, Phase[(12,19)])<br>
<br>
For a large number of pairs, cohere_pairs can be much more<br>
efficient than just calling cohere for each pair, because it<br>
caches most of the intensive computations. If N is the number of<br>
pairs, this function is O(N) for most of the heavy lifting,<br>
whereas calling cohere for each pair is O(N^2). However, because<br>
of the caching, it is also more memory intensive, making 2<br>
additional complex arrays with approximately the same number of<br>
elements as X.<br>
<br>
The parameter 'preferSpeedOverMemory', if false, limits the<br>
caching by only making one, rather than two, complex cache arrays.<br>
This is useful if memory becomes critical. Even when<br>
preferSpeedOverMemory is false, cohere_pairs will still give<br>
significant performace gains over calling cohere for each pair,<br>
and will use subtantially less memory than if<br>
preferSpeedOverMemory is true. In my tests with a 43000,64 array<br>
over all nonredundant pairs, preferSpeedOverMemory=1 delivered a<br>
33% performace boost on a 1.7GHZ Athlon with 512MB RAM compared<br>
with preferSpeedOverMemory=0. But both solutions were more than<br>
10x faster than naievly crunching all possible pairs through<br>
cohere.<br>
<br>
See test/cohere_pairs_test.py in the src tree for an example<br>
script that shows that this cohere_pairs and cohere give the same<br>
results for a given pair.</tt></dd></dl>
<dl><dt><a name="-conv"><strong>conv</strong></a>(x, y, mode<font color="#909090">=2</font>)</dt><dd><tt>convolve x with y</tt></dd></dl>
<dl><dt><a name="-corrcoef"><strong>corrcoef</strong></a>(*args)</dt><dd><tt><a href="#-corrcoef">corrcoef</a>(X) where X is a matrix returns a matrix of correlation<br>
coefficients for each numrows observations and numcols variables.<br>
<br>
<a href="#-corrcoef">corrcoef</a>(x,y) where x and y are vectors returns the matrix or<br>
correlation coefficients for x and y.<br>
<br>
Numeric arrays can be real or complex<br>
<br>
The correlation matrix is defined from the covariance matrix C as<br>
<br>
r(i,j) = C[i,j] / sqrt(C[i,i]*C[j,j])</tt></dd></dl>
<dl><dt><a name="-csd"><strong>csd</strong></a>(x, y, NFFT<font color="#909090">=256</font>, Fs<font color="#909090">=2</font>, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_hanning></font>, noverlap<font color="#909090">=0</font>)</dt><dd><tt>The cross spectral density Pxy by Welches average periodogram<br>
method. The vectors x and y are divided into NFFT length<br>
segments. Each segment is detrended by function detrend and<br>
windowed by function window. noverlap gives the length of the<br>
overlap between segments. The product of the direct FFTs of x and<br>
y are averaged over each segment to compute Pxy, with a scaling to<br>
correct for power loss due to windowing. Fs is the sampling<br>
frequency.<br>
<br>
NFFT must be a power of 2<br>
<br>
Returns the tuple Pxy, freqs<br>
<br>
<br>
<br>
Refs:<br>
Bendat & Piersol -- Random Data: Analysis and Measurement<br>
Procedures, John Wiley & Sons (1986)</tt></dd></dl>
<dl><dt><a name="-detrend"><strong>detrend</strong></a>(x, key<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="-detrend_linear"><strong>detrend_linear</strong></a>(x)</dt><dd><tt>Return x minus best fit line; 'linear' detrending</tt></dd></dl>
<dl><dt><a name="-detrend_mean"><strong>detrend_mean</strong></a>(x)</dt><dd><tt>Return x minus the <a href="#-mean">mean</a>(x)</tt></dd></dl>
<dl><dt><a name="-detrend_none"><strong>detrend_none</strong></a>(x)</dt><dd><tt>Return x: no detrending</tt></dd></dl>
<dl><dt><a name="-diagonal_matrix"><strong>diagonal_matrix</strong></a>(diag)</dt><dd><tt>Return square diagonal matrix whose non-zero elements are given by the<br>
input array.</tt></dd></dl>
<dl><dt><a name="-dist"><strong>dist</strong></a>(x, y)</dt><dd><tt>return the distance between two points</tt></dd></dl>
<dl><dt><a name="-dist_point_to_segment"><strong>dist_point_to_segment</strong></a>(p, s0, s1)</dt><dd><tt>get the distance of a point to a segment.<br>
<br>
p, s0, s1 are xy sequences<br>
<br>
This algorithm from<br>
<a href="http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm#Distance%20to%20Ray%20or%20Segment">http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm#Distance%20to%20Ray%20or%20Segment</a></tt></dd></dl>
<dl><dt><a name="-donothing_callback"><strong>donothing_callback</strong></a>(*args)</dt></dl>
<dl><dt><a name="-entropy"><strong>entropy</strong></a>(y, bins)</dt><dd><tt>Return the entropy of the data in y<br>
<br>
\sum p_i <a href="#-log2">log2</a>(p_i) where p_i is the probability of observing y in<br>
the ith bin of bins. bins can be a number of bins or a range of<br>
bins; see hist<br>
<br>
Compare S with analytic calculation for a Gaussian<br>
x = mu + sigma*randn(200000)<br>
Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) )</tt></dd></dl>
<dl><dt><a name="-exp_safe"><strong>exp_safe</strong></a>(x)</dt><dd><tt>Compute exponentials which safely underflow to zero.<br>
<br>
Slow but convenient to use. Note that NumArray will introduce proper<br>
floating point exception handling with access to the underlying<br>
hardware.</tt></dd></dl>
<dl><dt><a name="-find"><strong>find</strong></a>(condition)</dt><dd><tt>Return the indices where condition is true</tt></dd></dl>
<dl><dt><a name="-fix"><strong>fix</strong></a>(x)</dt><dd><tt>Rounds towards zero.<br>
x_rounded = <a href="#-fix">fix</a>(x) rounds the elements of x to the nearest integers<br>
towards zero.<br>
For negative numbers is equivalent to ceil and for positive to floor.</tt></dd></dl>
<dl><dt><a name="-frange"><strong>frange</strong></a>(xini, xfin<font color="#909090">=None</font>, delta<font color="#909090">=None</font>, **kw)</dt><dd><tt><a href="#-frange">frange</a>([start,] stop[, step, keywords]) -> array of floats<br>
<br>
Return a Numeric <a href="#-array">array</a>() containing a progression of floats. Similar to<br>
<a href="#-arange">arange</a>(), but defaults to a closed interval.<br>
<br>
<a href="#-frange">frange</a>(x0, x1) returns [x0, x0+1, x0+2, ..., x1]; start defaults to 0, and<br>
the endpoint *is included*. This behavior is different from that of<br>
range() and <a href="#-arange">arange</a>(). This is deliberate, since frange will probably be<br>
more useful for generating lists of points for function evaluation, and<br>
endpoints are often desired in this use. The usual behavior of range() can<br>
be obtained by setting the keyword 'closed=0', in this case <a href="#-frange">frange</a>()<br>
basically becomes <a href="#-arange">arange</a>().<br>
<br>
When step is given, it specifies the increment (or decrement). All<br>
arguments can be floating point numbers.<br>
<br>
<a href="#-frange">frange</a>(x0,x1,d) returns [x0,x0+d,x0+2d,...,xfin] where xfin<=x1.<br>
<br>
frange can also be called with the keyword 'npts'. This sets the number of<br>
points the list should contain (and overrides the value 'step' might have<br>
been given). <a href="#-arange">arange</a>() doesn't offer this option.<br>
<br>
Examples:<br>
>>> <a href="#-frange">frange</a>(3)<br>
<a href="#-array">array</a>([ 0., 1., 2., 3.])<br>
>>> <a href="#-frange">frange</a>(3,closed=0)<br>
<a href="#-array">array</a>([ 0., 1., 2.])<br>
>>> <a href="#-frange">frange</a>(1,6,2)<br>
<a href="#-array">array</a>([1, 3, 5])<br>
>>> <a href="#-frange">frange</a>(1,6.5,npts=5)<br>
<a href="#-array">array</a>([ 1. , 2.375, 3.75 , 5.125, 6.5 ])</tt></dd></dl>
<dl><dt><a name="-fromfunction_kw"><strong>fromfunction_kw</strong></a>(function, dimensions, **kwargs)</dt><dd><tt>Drop-in replacement for fromfunction() from Numerical Python.<br>
<br>
Allows passing keyword arguments to the desired function.<br>
<br>
Call it as (keywords are optional):<br>
<a href="#-fromfunction_kw">fromfunction_kw</a>(MyFunction, dimensions, keywords)<br>
<br>
The function MyFunction() is responsible for handling the dictionary of<br>
keywords it will recieve.</tt></dd></dl>
<dl><dt><a name="-get_sparse_matrix"><strong>get_sparse_matrix</strong></a>(M, N, frac<font color="#909090">=0.10000000000000001</font>)</dt><dd><tt>return a MxN sparse matrix with frac elements randomly filled</tt></dd></dl>
<dl><dt><a name="-get_xyz_where"><strong>get_xyz_where</strong></a>(Z, Cond)</dt><dd><tt>Z and Cond are MxN matrices. Z are data and Cond is a boolean<br>
matrix where some condition is satisfied. Return value is x,y,z<br>
where x and y are the indices into Z and z are the values of Z at<br>
those indices. x,y,z are 1D arrays</tt></dd></dl>
<dl><dt><a name="-hist"><strong>hist</strong></a>(y, bins<font color="#909090">=10</font>, normed<font color="#909090">=0</font>)</dt><dd><tt>Return the histogram of y with bins equally sized bins. If bins<br>
is an array, use the bins. Return value is<br>
(n,x) where n is the count for each bin in x<br>
<br>
If normed is False, return the counts in the first element of the<br>
return tuple. If normed is True, return the probability density<br>
n/(len(y)*dbin)<br>
<br>
If y has rank>1, it will be raveled<br>
Credits: the Numeric 22 documentation</tt></dd></dl>
<dl><dt><a name="-identity"><strong>identity</strong></a>(n, rank<font color="#909090">=2</font>, typecode<font color="#909090">='l'</font>)</dt><dd><tt><a href="#-identity">identity</a>(n,r) returns the identity matrix of shape (n,n,...,n) (rank r).<br>
<br>
For ranks higher than 2, this object is simply a multi-index Kronecker<br>
delta:<br>
/ 1 if i0=i1=...=iR,<br>
id[i0,i1,...,iR] = -|<br>
\ 0 otherwise.<br>
<br>
Optionally a typecode may be given (it defaults to 'l').<br>
<br>
Since rank defaults to 2, this function behaves in the default case (when<br>
only n is given) like the Numeric identity function.</tt></dd></dl>
<dl><dt><a name="-ispower2"><strong>ispower2</strong></a>(n)</dt><dd><tt>Returns the log base 2 of n if n is a power of 2, zero otherwise.<br>
<br>
Note the potential ambiguity if n==1: 2**0==1, interpret accordingly.</tt></dd></dl>
<dl><dt><a name="-l1norm"><strong>l1norm</strong></a>(a)</dt><dd><tt>Return the l1 norm of a, flattened out.<br>
<br>
Implemented as a separate function (not a call to <a href="#-norm">norm</a>() for speed).</tt></dd></dl>
<dl><dt><a name="-l2norm"><strong>l2norm</strong></a>(a)</dt><dd><tt>Return the l2 norm of a, flattened out.<br>
<br>
Implemented as a separate function (not a call to <a href="#-norm">norm</a>() for speed).</tt></dd></dl>
<dl><dt><a name="-levypdf"><strong>levypdf</strong></a>(x, gamma, alpha)</dt><dd><tt>Returm the levy pdf evaluated at x for params gamma, alpha</tt></dd></dl>
<dl><dt><a name="-linspace"><strong>linspace</strong></a>(xmin, xmax, N)</dt></dl>
<dl><dt><a name="-log2"><strong>log2</strong></a>(x, ln2<font color="#909090">=0.69314718055994529</font>)</dt><dd><tt>Return the log(x) in base 2.<br>
<br>
This is a _slow_ function but which is guaranteed to return the correct<br>
integer value if the input is an ineger exact power of 2.</tt></dd></dl>
<dl><dt><a name="-longest_contiguous_ones"><strong>longest_contiguous_ones</strong></a>(x)</dt><dd><tt>return the indicies of the longest stretch of contiguous ones in x,<br>
assuming x is a vector of zeros and ones.</tt></dd></dl>
<dl><dt><a name="-longest_ones"><strong>longest_ones</strong></a>(x)</dt><dd><tt>return the indicies of the longest stretch of contiguous ones in x,<br>
assuming x is a vector of zeros and ones.<br>
<br>
If there are two equally long stretches, pick the first</tt></dd></dl>
<dl><dt><a name="-mean"><strong>mean</strong></a>(x, dim<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="-mean_flat"><strong>mean_flat</strong></a>(a)</dt><dd><tt>Return the mean of all the elements of a, flattened out.</tt></dd></dl>
<dl><dt><a name="-meshgrid"><strong>meshgrid</strong></a>(x, y)</dt><dd><tt>For vectors x, y with lengths Nx=len(x) and Ny=len(y), return X, Y<br>
where X and Y are (Ny, Nx) shaped arrays with the elements of x<br>
and y repeated to fill the matrix<br>
<br>
EG,<br>
<br>
[X, Y] = <a href="#-meshgrid">meshgrid</a>([1,2,3], [4,5,6,7])<br>
<br>
X =<br>
1 2 3<br>
1 2 3<br>
1 2 3<br>
1 2 3<br>
<br>
<br>
Y =<br>
4 4 4<br>
5 5 5<br>
6 6 6<br>
7 7 7</tt></dd></dl>
<dl><dt><a name="-mfuncC"><strong>mfuncC</strong></a>(f, x)</dt><dd><tt><a href="#-mfuncC">mfuncC</a>(f, x) : matrix function with possibly complex eigenvalues.<br>
Note: Numeric defines (v,u) = eig(x) => x*u.T = u.T * Diag(v)<br>
This function is needed by sqrtm and allows further functions.</tt></dd></dl>
<dl><dt><a name="-norm"><strong>norm</strong></a>(a, p<font color="#909090">=2</font>)</dt><dd><tt><a href="#-norm">norm</a>(a,p=2) -> l-p norm of a.flat<br>
<br>
Return the l-p norm of a, considered as a flat array. This is NOT a true<br>
matrix norm, since arrays of arbitrary rank are always flattened.<br>
<br>
p can be a number or the string 'Infinity' to get the L-infinity norm.</tt></dd></dl>
<dl><dt><a name="-normpdf"><strong>normpdf</strong></a>(x, *args)</dt><dd><tt>Return the normal pdf evaluated at x; args provides mu, sigma</tt></dd></dl>
<dl><dt><a name="-orth"><strong>orth</strong></a>(A)</dt><dd><tt>Orthogonalization procedure by Matlab.<br>
The description is taken from its help:<br>
<br>
Q = ORTH(A) is an orthonormal basis for the range of A.<br>
That is, Q'*Q = I, the columns of Q span the same space as <br>
the columns of A, and the number of columns of Q is the <br>
rank of A.</tt></dd></dl>
<dl><dt><a name="-polyfit"><strong>polyfit</strong></a>(x, y, N)</dt><dd><tt>Do a best fit polynomial of order N of y to x. Return value is a<br>
vector of polynomial coefficients [pk ... p1 p0]. Eg, for N=2<br>
<br>
p2*x0^2 + p1*x0 + p0 = y1<br>
p2*x1^2 + p1*x1 + p0 = y1<br>
p2*x2^2 + p1*x2 + p0 = y2<br>
.....<br>
p2*xk^2 + p1*xk + p0 = yk<br>
<br>
<br>
Method: if X is a the Vandermonde Matrix computed from x (see<br>
<a href="http://mathworld.wolfram.com/VandermondeMatrix.html">http://mathworld.wolfram.com/VandermondeMatrix.html</a>), then the<br>
polynomial least squares solution is given by the 'p' in<br>
<br>
X*p = y<br>
<br>
where X is a len(x) x N+1 matrix, p is a N+1 length vector, and y<br>
is a len(x) x 1 vector<br>
<br>
This equation can be solved as<br>
<br>
p = (XT*X)^-1 * XT * y<br>
<br>
where XT is the transpose of X and -1 denotes the inverse.<br>
<br>
For more info, see<br>
<a href="http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html">http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html</a>,<br>
but note that the k's and n's in the superscripts and subscripts<br>
on that page. The linear algebra is correct, however.<br>
<br>
See also polyval</tt></dd></dl>
<dl><dt><a name="-polyval"><strong>polyval</strong></a>(p, x)</dt><dd><tt>y = <a href="#-polyval">polyval</a>(p,x)<br>
<br>
p is a vector of polynomial coeffients and y is the polynomial<br>
evaluated at x.<br>
<br>
Example code to remove a polynomial (quadratic) trend from y:<br>
<br>
p = <a href="#-polyfit">polyfit</a>(x, y, 2)<br>
trend = <a href="#-polyval">polyval</a>(p, x)<br>
resid = y - trend<br>
<br>
See also polyfit</tt></dd></dl>
<dl><dt><a name="-prctile"><strong>prctile</strong></a>(x, p<font color="#909090">=(0.0, 25.0, 50.0, 75.0, 100.0)</font>)</dt><dd><tt>Return the percentiles of x. p can either be a sequence of<br>
percentil values or a scalar. If p is a sequence the i-th element<br>
of the return sequence is the p(i)-th percentile of x</tt></dd></dl>
<dl><dt><a name="-prepca"><strong>prepca</strong></a>(P, frac<font color="#909090">=0</font>)</dt><dd><tt>Compute the principal components of P. P is a numVars x<br>
numObservations numeric array. frac is the minimum fraction of<br>
variance that a component must contain to be included<br>
<br>
Return value are<br>
Pcomponents : a num components x num observations numeric array<br>
Trans : the weights matrix, ie, Pcomponents = Trans*P<br>
fracVar : the fraction of the variance accounted for by each<br>
component returned</tt></dd></dl>
<dl><dt><a name="-psd"><strong>psd</strong></a>(x, NFFT<font color="#909090">=256</font>, Fs<font color="#909090">=2</font>, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_hanning></font>, noverlap<font color="#909090">=0</font>)</dt><dd><tt>The power spectral density by Welches average periodogram method.<br>
The vector x is divided into NFFT length segments. Each segment<br>
is detrended by function detrend and windowed by function window.<br>
noperlap gives the length of the overlap between segments. The<br>
absolute(fft(segment))**2 of each segment are averaged to compute Pxx,<br>
with a scaling to correct for power loss due to windowing. Fs is<br>
the sampling frequency.<br>
<br>
-- NFFT must be a power of 2<br>
-- detrend and window are functions, unlike in matlab where they are<br>
vectors.<br>
-- if length x < NFFT, it will be zero padded to NFFT<br>
<br>
<br>
Returns the tuple Pxx, freqs<br>
<br>
Refs:<br>
Bendat & Piersol -- Random Data: Analysis and Measurement<br>
Procedures, John Wiley & Sons (1986)</tt></dd></dl>
<dl><dt><a name="-rank"><strong>rank</strong></a>(x)</dt><dd><tt>Returns the rank of a matrix.<br>
The rank is understood here as the an estimation of the number of<br>
linearly independent rows or columns (depending on the size of the<br>
matrix).<br>
Note that numerix.mlab.<a href="#-rank">rank</a>() is not equivalent to Matlab's rank.<br>
This function is!</tt></dd></dl>
<dl><dt><a name="-rem"><strong>rem</strong></a>(x, y)</dt><dd><tt>Remainder after division.<br>
<a href="#-rem">rem</a>(x,y) is equivalent to x - y.*<a href="#-fix">fix</a>(x./y) in case y is not zero.<br>
By convention, <a href="#-rem">rem</a>(x,0) returns None.<br>
We keep the convention by Matlab:<br>
"The input x and y must be real arrays of the same size, or real scalars."</tt></dd></dl>
<dl><dt><a name="-reshape"><strong>reshape</strong></a>(...)</dt><dd><tt><a href="#-reshape">reshape</a>(a, (d1, d2, ..., dn)). Change the shape of a to be an n-dimensional array with dimensions given by d1...dn. Note: the size specified for the new array must be exactly equal to the size of the old one or an error will occur.</tt></dd></dl>
<dl><dt><a name="-rk4"><strong>rk4</strong></a>(derivs, y0, t)</dt><dd><tt>Integrate 1D or ND system of ODEs from initial state y0 at sample<br>
times t. derivs returns the derivative of the system and has the<br>
signature<br>
<br>
dy = derivs(yi, ti)<br>
<br>
Example 1 :<br>
<br>
## 2D system<br>
# Numeric solution<br>
def derivs6(x,t):<br>
d1 = x[0] + 2*x[1]<br>
d2 = -3*x[0] + 4*x[1]<br>
return (d1, d2)<br>
dt = 0.0005<br>
t = <a href="#-arange">arange</a>(0.0, 2.0, dt)<br>
y0 = (1,2)<br>
yout = <a href="#-rk4">rk4</a>(derivs6, y0, t)<br>
<br>
Example 2:<br>
<br>
## 1D system<br>
alpha = 2<br>
def derivs(x,t):<br>
return -alpha*x + exp(-t)<br>
<br>
y0 = 1<br>
yout = <a href="#-rk4">rk4</a>(derivs, y0, t)</tt></dd></dl>
<dl><dt><a name="-rms_flat"><strong>rms_flat</strong></a>(a)</dt><dd><tt>Return the root mean square of all the elements of a, flattened out.</tt></dd></dl>
<dl><dt><a name="-searchsorted"><strong>searchsorted</strong></a> = binarysearch(...)</dt><dd><tt>binarysearch(a,v)</tt></dd></dl>
<dl><dt><a name="-segments_intersect"><strong>segments_intersect</strong></a>(s1, s2)</dt><dd><tt>Return True if s1 and s2 intersect.<br>
s1 and s2 are defines as<br>
<br>
s1: (x1, y1), (x2, y2)<br>
s2: (x3, y3), (x4, y4)</tt></dd></dl>
<dl><dt><a name="-specgram"><strong>specgram</strong></a>(x, NFFT<font color="#909090">=256</font>, Fs<font color="#909090">=2</font>, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_hanning></font>, noverlap<font color="#909090">=128</font>)</dt><dd><tt>Compute a spectrogram of data in x. Data are split into NFFT<br>
length segements and the PSD of each section is computed. The<br>
windowing function window is applied to each segment, and the<br>
amount of overlap of each segment is specified with noverlap<br>
<br>
See pdf for more info.<br>
<br>
The returned times are the midpoints of the intervals over which<br>
the ffts are calculated</tt></dd></dl>
<dl><dt><a name="-sqrtm"><strong>sqrtm</strong></a>(x)</dt><dd><tt>Returns the square root of a square matrix.<br>
This means that s=<a href="#-sqrtm">sqrtm</a>(x) implies s*s = x.<br>
Note that s and x are matrices.</tt></dd></dl>
<dl><dt><a name="-sum_flat"><strong>sum_flat</strong></a>(a)</dt><dd><tt>Return the sum of all the elements of a, flattened out.<br>
<br>
It uses a.flat, and if a is not contiguous, a call to ravel(a) is made.</tt></dd></dl>
<dl><dt><a name="-take"><strong>take</strong></a>(...)</dt><dd><tt><a href="#-take">take</a>(a, indices, axis=0). Selects the elements in indices from array a along the given axis.</tt></dd></dl>
<dl><dt><a name="-trapz"><strong>trapz</strong></a>(x, y)</dt></dl>
<dl><dt><a name="-vander"><strong>vander</strong></a>(x, N<font color="#909090">=None</font>)</dt><dd><tt>X = <a href="#-vander">vander</a>(x,N=None)<br>
<br>
The Vandermonde matrix of vector x. The i-th column of X is the<br>
the i-th power of x. N is the maximum power to compute; if N is<br>
None it defaults to len(x).</tt></dd></dl>
<dl><dt><a name="-window_hanning"><strong>window_hanning</strong></a>(x)</dt><dd><tt>return x times the hanning window of len(x)</tt></dd></dl>
<dl><dt><a name="-window_none"><strong>window_none</strong></a>(x)</dt><dd><tt>No window function; simply return x</tt></dd></dl>
<dl><dt><a name="-zeros"><strong>zeros</strong></a>(...)</dt><dd><tt><a href="#-zeros">zeros</a>((d1,...,dn),typecode='l',savespace=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero. If savespace is nonzero the array will be a spacesaver array.</tt></dd></dl>
<dl><dt><a name="-zeros_like"><strong>zeros_like</strong></a>(a)</dt><dd><tt>Return an array of zeros of the shape and typecode of a.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>Complex</strong> = 'D'<br>
<strong>Float</strong> = 'd'<br>
<strong>Int</strong> = 'l'<br>
<strong>absolute</strong> = <ufunc 'absolute'><br>
<strong>arctan2</strong> = <ufunc 'arctan2'><br>
<strong>ceil</strong> = <ufunc 'ceil'><br>
<strong>conjugate</strong> = <ufunc 'conjugate'><br>
<strong>divide</strong> = <ufunc 'divide'><br>
<strong>division</strong> = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)<br>
<strong>exp</strong> = <ufunc 'exp'><br>
<strong>exp_safe_MAX</strong> = 1.7976931348623157e+308<br>
<strong>exp_safe_MIN</strong> = -708.39641853226408<br>
<strong>floor</strong> = <ufunc 'floor'><br>
<strong>log</strong> = <ufunc 'log'><br>
<strong>multiply</strong> = <ufunc 'multiply'><br>
<strong>pi</strong> = 3.1415926535897931<br>
<strong>power</strong> = <ufunc 'power'><br>
<strong>readme</strong> = '<font color="#c040c0">\n</font>MLab2.py, release 1<font color="#c040c0">\n\n</font>Created on February 2003 b...<font color="#c040c0">\n</font>Look at: http://pdilib.sf.net for new releases.<font color="#c040c0">\n</font>'<br>
<strong>verbose</strong> = <matplotlib.Verbose instance></td></tr></table>
@footer@