764 lines (753 with data), 66.3 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/lib64/python2.4/site-packages/matplotlib/mlab.py">/usr/lib64/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="matplotlib.numerix.html">matplotlib.numerix</a><br>
</td><td width="25%" valign=top><a href="matplotlib.nxutils.html">matplotlib.nxutils</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></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="matplotlib.mlab.html#FIFOBuffer">FIFOBuffer</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="FIFOBuffer">class <strong>FIFOBuffer</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A FIFO queue to hold incoming x, y data in a rotating buffer using<br>
numerix arrrays under the hood. It is assumed that you will call<br>
asarrays much less frequently than you add data to the queue --<br>
otherwise another data structure will be faster<br>
<br>
This can be used to support plots where data is added from a real<br>
time feed and the plot object wants grab data from the buffer and<br>
plot it to screen less freqeuently than the incoming<br>
<br>
If you set the dataLim attr to a matplotlib BBox (eg ax.dataLim),<br>
the dataLim will be updated as new data come in<br>
<br>
TODI: add a grow method that will extend nmax<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="FIFOBuffer-__init__"><strong>__init__</strong></a>(self, nmax)</dt><dd><tt>buffer up to nmax points</tt></dd></dl>
<dl><dt><a name="FIFOBuffer-add"><strong>add</strong></a>(self, x, y)</dt><dd><tt>add scalar x and y to the queue</tt></dd></dl>
<dl><dt><a name="FIFOBuffer-asarrays"><strong>asarrays</strong></a>(self)</dt><dd><tt>return x and y as arrays; their length will be the len of data<br>
added or nmax</tt></dd></dl>
<dl><dt><a name="FIFOBuffer-last"><strong>last</strong></a>(self)</dt><dd><tt>get the last x, y or None, None if no data set</tt></dd></dl>
<dl><dt><a name="FIFOBuffer-register"><strong>register</strong></a>(self, func, N)</dt><dd><tt>call func everytime N events are passed; func signature is func(fifo)</tt></dd></dl>
<dl><dt><a name="FIFOBuffer-update_datalim_to_current"><strong>update_datalim_to_current</strong></a>(self)</dt><dd><tt>update the datalim in the current data in the fifo</tt></dd></dl>
</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.array(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="-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, window, 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="-concatenate"><strong>concatenate</strong></a>(...)</dt><dd><tt><a href="#-concatenate">concatenate</a>((a1, a2, ...), axis=0)<br>
<br>
Join arrays together.<br>
<br>
The tuple of sequences (a1, a2, ...) are joined along the given axis<br>
(default is the first one) into a single numpy array.<br>
<br>
Example:<br>
<br>
>>> <a href="#-concatenate">concatenate</a>( ([0,1,2], [5,6,7]) )<br>
array([0, 1, 2, 5, 6, 7])</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>
window can be a function or a vector of length NFFT. To create <br>
window vectors see numpy.blackman, numpy.hamming, numpy.bartlett,<br>
scipy.signal, scipy.signal.get_window etc.<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="-dot"><strong>dot</strong></a>(...)</dt><dd><tt><a href="#-dot">dot</a>(a,b)<br>
Returns the dot product of a and b for arrays of floating point types.<br>
Like the generic numpy equivalent the product sum is over<br>
the last dimension of a and the second-to-last dimension of b.<br>
NB: The first argument is not conjugated.</tt></dd></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="-fftsurr"><strong>fftsurr</strong></a>(x, detrend<font color="#909090">=<function detrend_none></font>, window<font color="#909090">=<function window_none></font>)</dt><dd><tt>Compute an FFT phase randomized surrogate of x</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 array() containing a progression of floats. Similar to<br>
arange(), 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 arange(). 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 arange().<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). arange() doesn't offer this option.<br>
<br>
Examples:<br>
>>> <a href="#-frange">frange</a>(3)<br>
array([ 0., 1., 2., 3.])<br>
>>> <a href="#-frange">frange</a>(3,closed=0)<br>
array([ 0., 1., 2.])<br>
>>> <a href="#-frange">frange</a>(1,6,2)<br>
array([1, 3, 5])<br>
>>> <a href="#-frange">frange</a>(1,6.5,npts=5)<br>
array([ 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="-inside_poly"><strong>inside_poly</strong></a>(points, verts)</dt><dd><tt>"<br>
points is a sequence of x,y points<br>
verts is a sequence of x,y vertices of a poygon<br>
<br>
return value is a sequence on indices into points for the points<br>
that are inside the polygon</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="-liaupunov"><strong>liaupunov</strong></a>(x, fprime)</dt><dd><tt>x is a very long trajectory from a map, and fprime returns the<br>
derivative of x. Return lambda = 1/n\sum ln|fprime(x_i)|. See Sec<br>
10.5 Strogatz (1994)"Nonlinear Dynamics and Chaos".</tt></dd></dl>
<dl><dt><a name="-linspace"><strong>linspace</strong></a>(xmin, xmax, N)</dt></dl>
<dl><dt><a name="-load"><strong>load</strong></a>(fname, comments<font color="#909090">='#'</font>, delimiter<font color="#909090">=None</font>, converters<font color="#909090">=None</font>, skiprows<font color="#909090">=0</font>, usecols<font color="#909090">=None</font>, unpack<font color="#909090">=False</font>)</dt><dd><tt>Load ASCII data from fname into an array and return the array.<br>
<br>
The data must be regular, same number of values in every row<br>
<br>
fname can be a filename or a file handle. Support for gzipped files is<br>
automatic, if the filename ends in .gz<br>
<br>
matfile data is not currently supported, but see<br>
Nigel Wade's matfile <a href="ftp://ion.le.ac.uk/matfile/matfile.tar.gz">ftp://ion.le.ac.uk/matfile/matfile.tar.gz</a><br>
<br>
Example usage:<br>
<br>
X = <a href="#-load">load</a>('test.dat') # data in two columns<br>
t = X[:,0]<br>
y = X[:,1]<br>
<br>
Alternatively, you can do the same with "unpack"; see below<br>
<br>
X = <a href="#-load">load</a>('test.dat') # a matrix of data<br>
x = <a href="#-load">load</a>('test.dat') # a single column of data<br>
<br>
comments - the character used to indicate the start of a comment<br>
in the file<br>
<br>
delimiter is a string-like character used to seperate values in the<br>
file. If delimiter is unspecified or none, any whitespace string is<br>
a separator.<br>
<br>
converters, if not None, is a dictionary mapping column number to<br>
a function that will convert that column to a float. Eg, if<br>
column 0 is a date string: converters={0:datestr2num}<br>
<br>
skiprows is the number of rows from the top to skip<br>
<br>
usecols, if not None, is a sequence of integer column indexes to<br>
extract where 0 is the first column, eg usecols=(1,4,5) to extract<br>
just the 2nd, 5th and 6th columns<br>
<br>
unpack, if True, will transpose the matrix allowing you to unpack<br>
into named arguments on the left hand side<br>
<br>
t,y = <a href="#-load">load</a>('test.dat', unpack=True) # for two column data<br>
x,y,z = <a href="#-load">load</a>('somefile.dat', usecols=(3,5,7), unpack=True)<br>
<br>
See examples/load_demo.py which exeercises many of these options.</tt></dd></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="-logspace"><strong>logspace</strong></a>(xmin, xmax, N)</dt></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="-matrixmultiply"><strong>matrixmultiply</strong></a> = dot(...)</dt><dd><tt><a href="#-dot">dot</a>(a,b)<br>
Returns the dot product of a and b for arrays of floating point types.<br>
Like the generic numpy equivalent the product sum is over<br>
the last dimension of a and the second-to-last dimension of b.<br>
NB: The first argument is not conjugated.</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="-movavg"><strong>movavg</strong></a>(x, n)</dt><dd><tt>compute the len(n) moving average of x</tt></dd></dl>
<dl><dt><a name="-norm"><strong>norm</strong></a>(x, y<font color="#909090">=2</font>)</dt><dd><tt>Norm of a matrix or a vector according to Matlab.<br>
The description is taken from Matlab:<br>
<br>
For matrices...<br>
NORM(X) is the largest singular value of X, max(svd(X)).<br>
NORM(X,2) is the same as NORM(X).<br>
NORM(X,1) is the 1-norm of X, the largest column sum,<br>
= max(sum(abs((X)))).<br>
NORM(X,inf) is the infinity norm of X, the largest row sum,<br>
= max(sum(abs((X')))).<br>
NORM(X,'fro') is the Frobenius norm, sqrt(sum(diag(X'*X))).<br>
NORM(X,P) is available for matrix X only if P is 1, 2, inf or 'fro'.<br>
<br>
For vectors...<br>
NORM(V,P) = sum(abs(V).^P)^(1/P).<br>
NORM(V) = <a href="#-norm">norm</a>(V,2).<br>
NORM(V,inf) = max(abs(V)).<br>
NORM(V,-inf) = min(abs(V)).</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 is a functions, unlike in matlab where it is a vector.<br>
-- window can be a function or a vector of length NFFT. To create window<br>
vectors see numpy.blackman, numpy.hamming, numpy.bartlett,<br>
scipy.signal, scipy.signal.get_window etc.<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="-rand"><strong>rand</strong></a>(...)</dt><dd><tt>Return an array of the given dimensions which is initialized to <br>
random numbers from a uniform distribution in the range [0,1).<br>
<br>
<a href="#-rand">rand</a>(d0, d1, ..., dn) -> random values<br>
<br>
Note: This is a convenience function. If you want an<br>
interface that takes a tuple as the first argument<br>
use numpy.random.random_sample(shape_tuple).</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="-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 = arange(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="-save"><strong>save</strong></a>(fname, X, fmt<font color="#909090">='%.18e'</font>, delimiter<font color="#909090">=' '</font>)</dt><dd><tt>Save the data in X to file fname using fmt string to convert the<br>
data to strings<br>
<br>
fname can be a filename or a file handle. If the filename ends in .gz,<br>
the file is automatically saved in compressed gzip format. The <a href="#-load">load</a>()<br>
command understands gzipped files transparently.<br>
<br>
Example usage:<br>
<br>
<a href="#-save">save</a>('test.out', X) # X is an array<br>
<a href="#-save">save</a>('test1.out', (x,y,z)) # x,y,z equal sized 1D arrays<br>
<a href="#-save">save</a>('test2.out', x) # x is 1D<br>
<a href="#-save">save</a>('test3.out', x, fmt='%1.4e') # use exponential notation<br>
<br>
delimiter is used to separate the fields, eg delimiter ',' for<br>
comma-separated values</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="-slopes"><strong>slopes</strong></a>(x, y)</dt><dd><tt>SLOPES calculate the slope y'(x) Given data vectors X and Y SLOPES<br>
calculates Y'(X), i.e the slope of a curve Y(X). The slope is<br>
estimated using the slope obtained from that of a parabola through<br>
any three consecutive points.<br>
<br>
This method should be superior to that described in the appendix<br>
of A CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russel<br>
W. Stineman (Creative Computing July 1980) in at least one aspect:<br>
<br>
Circles for interpolation demand a known aspect ratio between x-<br>
and y-values. For many functions, however, the abscissa are given<br>
in different dimensions, so an aspect ratio is completely<br>
arbitrary.<br>
<br>
The parabola method gives very similar results to the circle<br>
method for most regular cases but behaves much better in special<br>
cases<br>
<br>
Norbert Nemec, Institute of Theoretical Physics, University or<br>
Regensburg, April 2006 Norbert.Nemec at physik.uni-regensburg.de<br>
<br>
(inspired by a original implementation by Halldor Bjornsson,<br>
Icelandic Meteorological Office, March 2006 halldor at vedur.is)</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>
window can be a function or a vector of length NFFT. To create<br>
window vectors see numpy.blackman, numpy.hamming, numpy.bartlett,<br>
scipy.signal, scipy.signal.get_window etc.<br>
<br>
<br>
See pdf for more info.<br>
<br>
If x is real (i.e. non-Complex) only the positive spectrum is<br>
given. If x is Complex then the complete spectrum is given.<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="-stineman_interp"><strong>stineman_interp</strong></a>(xi, x, y, yp<font color="#909090">=None</font>)</dt><dd><tt>STINEMAN_INTERP Well behaved data interpolation. Given data<br>
vectors X and Y, the slope vector YP and a new abscissa vector XI<br>
the function <a href="#-stineman_interp">stineman_interp</a>(xi,x,y,yp) uses Stineman<br>
interpolation to calculate a vector YI corresponding to XI.<br>
<br>
Here's an example that generates a coarse sine curve, then<br>
interpolates over a finer abscissa:<br>
<br>
x = <a href="#-linspace">linspace</a>(0,2*pi,20); y = sin(x); yp = cos(x)<br>
xi = <a href="#-linspace">linspace</a>(0,2*pi,40);<br>
yi = <a href="#-stineman_interp">stineman_interp</a>(xi,x,y,yp);<br>
plot(x,y,'o',xi,yi)<br>
<br>
The interpolation method is described in the article A<br>
CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russell<br>
W. Stineman. The article appeared in the July 1980 issue of<br>
Creative computing with a note from the editor stating that while<br>
they were<br>
<br>
not an academic journal but once in a while something serious<br>
and original comes in adding that this was<br>
"apparently a real solution" to a well known problem.<br>
<br>
For yp=None, the routine automatically determines the slopes using<br>
the "slopes" routine.<br>
<br>
X is assumed to be sorted in increasing order<br>
<br>
For values xi[j] < x[0] or xi[j] > x[-1], the routine tries a<br>
extrapolation. The relevance of the data obtained from this, of<br>
course, questionable...<br>
<br>
original implementation by Halldor Bjornsson, Icelandic<br>
Meteorolocial Office, March 2006 halldor at vedur.is<br>
<br>
completely reworked and optimized for Python by Norbert Nemec,<br>
Institute of Theoretical Physics, University or Regensburg, April<br>
2006 Norbert.Nemec at physik.uni-regensburg.de</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="-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_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@