33Numerical python functions written for compatability with matlab(TM)
44commands with the same names.
55
6- Matlab(TM) compatible functions:
6+ Matlab(TM) compatible functions
7+ -------------------------------
78
8- * cohere - Coherence (normalized cross spectral density)
9+ :func:`cohere`
10+ Coherence (normalized cross spectral density)
911
10- * csd - Cross spectral density uing Welch's average periodogram
12+ :func:`csd`
13+ Cross spectral density uing Welch's average periodogram
1114
12- * detrend -- Remove the mean or best fit line from an array
15+ :func:`detrend`
16+ Remove the mean or best fit line from an array
1317
14- * find - Return the indices where some condition is true;
15- numpy.nonzero is similar but more general.
18+ :func:`find`
19+ Return the indices where some condition is true;
20+ numpy.nonzero is similar but more general.
1621
17- * griddata - interpolate irregularly distributed data to a
18- regular grid.
22+ :func:`griddata`
23+ interpolate irregularly distributed data to a
24+ regular grid.
1925
20- * prctile - find the percentiles of a sequence
26+ :func:`prctile`
27+ find the percentiles of a sequence
2128
22- * prepca - Principal Component Analysis
29+ :func:`prepca`
30+ Principal Component Analysis
2331
24- * psd - Power spectral density uing Welch's average periodogram
32+ :func:`psd`
33+ Power spectral density uing Welch's average periodogram
2534
26- * rk4 - A 4th order runge kutta integrator for 1D or ND systems
35+ :func:`rk4`
36+ A 4th order runge kutta integrator for 1D or ND systems
2737
2838
29- The following are deprecated; please import directly from numpy
30- (with care--function signatures may differ):
39+ Miscellaneous functions
40+ -------------------------
3141
32- * conv - convolution (numpy.convolve)
33- * corrcoef - The matrix of correlation coefficients
34- * hist -- Histogram (numpy.histogram)
35- * linspace -- Linear spaced array from min to max
36- * meshgrid
37- * polyfit - least squares best polynomial fit of x to y
38- * polyval - evaluate a vector for a vector of polynomial coeffs
39- * trapz - trapeziodal integration (trapz(x,y) -> numpy.trapz(y,x))
40- * vander - the Vandermonde matrix
42+ Functions that don't exist in matlab(TM), but are useful anyway:
4143
42- Functions that don't exist in matlab(TM), but are useful anyway:
44+ :meth:`cohere_pairs`
45+ Coherence over all pairs. This is not a matlab function, but we
46+ compute coherence a lot in my lab, and we compute it for a lot of
47+ pairs. This function is optimized to do this efficiently by
48+ caching the direct FFTs.
4349
44- * cohere_pairs - Coherence over all pairs. This is not a matlab
45- function, but we compute coherence a lot in my lab, and we
46- compute it for a lot of pairs. This function is optimized to do
47- this efficiently by caching the direct FFTs.
50+ :meth:`rk4`
51+ A 4th order Runge-Kutta ODE integrator in case you ever find
52+ yourself stranded without scipy (and the far superior
53+ scipy.integrate tools)
4854
49- = record array helper functions =
50- * rec2txt : pretty print a record array
51- * rec2csv : store record array in CSV file
52- * csv2rec : import record array from CSV file with type inspection
53- * rec_append_fields: adds field(s)/array(s) to record array
54- * rec_drop_fields : drop fields from record array
55- * rec_join : join two record arrays on sequence of fields
56- * rec_groupby : summarize data by groups (similar to SQL GROUP BY)
57- * rec_summarize : helper code to filter rec array fields into new fields
55+ record array helper functions
56+ -------------------------------
57+
58+ A collection of helper methods for numpyrecord arrays
59+
60+ .. _htmlonly::
61+
62+ See :ref:`misc-examples-index`
63+
64+ :meth:`rec2txt`
65+ pretty print a record array
66+
67+ :meth:`rec2csv`
68+ store record array in CSV file
69+
70+ :meth:`csv2rec`
71+ import record array from CSV file with type inspection
72+
73+ :meth:`rec_append_fields`
74+ adds field(s)/array(s) to record array
75+
76+ :meth:`rec_drop_fields`
77+ drop fields from record array
78+
79+ :meth:`rec_join`
80+ join two record arrays on sequence of fields
81+
82+ :meth:`rec_groupby`
83+ summarize data by groups (similar to SQL GROUP BY)
84+
85+ :meth:`rec_summarize`
86+ helper code to filter rec array fields into new fields
5887
5988For the rec viewer functions(e rec2csv), there are a bunch of Format
6089objects you can pass into the functions that will do things like color
6190negative values red, set percent formatting and scaling, etc.
6291
63-
64- Example usage:
92+ Example usage::
6593
6694 r = csv2rec('somefile.csv', checkrows=0)
6795
82110 win.show_all()
83111 gtk.main()
84112
113+
114+ Deprecated functions
115+ ---------------------
116+
117+ The following are deprecated; please import directly from numpy (with
118+ care--function signatures may differ):
119+
120+ :meth:`conv`
121+ convolution (numpy.convolve)
122+
123+ :meth:`corrcoef`
124+ The matrix of correlation coefficients
125+
126+ :meth:`hist`
127+ Histogram (numpy.histogram)
128+
129+ :meth:`linspace`
130+ Linear spaced array from min to max
131+
132+ :meth:`meshgrid`
133+ Make a 2D grid from 2 1 arrays (numpy.meshgrid)
134+
135+ :meth:`polyfit`
136+ least squares best polynomial fit of x to y (numpy.polyfit)
137+
138+ :meth:`polyval`
139+ evaluate a vector for a vector of polynomial coeffs (numpy.polyval)
140+
141+ :meth:`trapz`
142+ trapeziodal integration (trapz(x,y) -> numpy.trapz(y,x))
143+
144+ :meth:`vander`
145+ the Vandermonde matrix (numpy.vander)
146+
85147"""
86148
87149from __future__ import division
@@ -185,19 +247,22 @@ def psd(x, NFFT=256, Fs=2, detrend=detrend_none,
185247 to calculate the Fourier frequencies, freqs, in cycles per time
186248 unit.
187249
188- -- NFFT must be even; a power 2 is most efficient.
189- -- detrend is a functions, unlike in matlab where it is a vector.
190- -- window can be a function or a vector of length NFFT. To create window
191- vectors see numpy.blackman, numpy.hamming, numpy.bartlett,
192- scipy.signal, scipy.signal.get_window etc.
193- -- if length x < NFFT, it will be zero padded to NFFT
250+ *NFFT*
251+ The length of the FFT window. Must be even; a power 2 is most efficient.
194252
253+ *detrend*
254+ is a function, unlike in matlab where it is a vector.
195255
196- Returns the tuple Pxx, freqs
256+ *window*
257+ can be a function or a vector of length NFFT. To create window
258+ vectors see numpy.blackman, numpy.hamming, numpy.bartlett,
259+ scipy.signal, scipy.signal.get_window etc.
197260
198- Refs:
199- Bendat & Piersol -- Random Data: Analysis and Measurement
200- Procedures, John Wiley & Sons (1986)
261+ If length x < NFFT, it will be zero padded to NFFT
262+
263+ Returns the tuple (*Pxx*, *freqs*)
264+
265+ Refs: Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
201266
202267 """
203268 # I think we could remove this condition without hurting anything.
@@ -409,7 +474,7 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none,
409474 window = window_hanning , noverlap = 0 ):
410475 """
411476 The coherence between x and y. Coherence is the normalized
412- cross spectral density
477+ cross spectral density:
413478
414479 .. math::
415480
@@ -470,7 +535,7 @@ def polyfit(x,y,N)
470535
471536
472537 Method: if X is a the Vandermonde Matrix computed from x (see
473- http://mathworld.wolfram.com/VandermondeMatrix.html), then the
538+ `vandermonds < http://mathworld.wolfram.com/VandermondeMatrix.html>`_ ), then the
474539 polynomial least squares solution is given by the 'p' in
475540
476541 X*p = y
@@ -487,7 +552,7 @@ def polyfit(x,y,N)
487552 numpy.linalg.lstsq.
488553
489554 For more info, see
490- http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html,
555+ `least squares fitting < http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html>`_ ,
491556 but note that the k's and n's in the superscripts and subscripts
492557 on that page. The linear algebra is correct, however.
493558
@@ -898,13 +963,20 @@ def center_matrix(M, dim=0):
898963
899964def rk4 (derivs , y0 , t ):
900965 """
901- Integrate 1D or ND system of ODEs from initial state y0 at sample
902- times t. derivs returns the derivative of the system and has the
903- signature
966+ Integrate 1D or ND system of ODEs using 4-th order Runge-Kutta. This is a toy implementation which may be useful if you find yourself stranded on a system w/o scipy. Otherwise use ``scipy.integrate``
967+
968+ *y0*
969+ initial state vector
970+
971+ *t*
972+ sample times
904973
905- dy = derivs(yi, ti)
974+ *derivs*
975+ returns the derivative of the system and has the
976+ signature ``dy = derivs(yi, ti)``
906977
907- Example 1 :
978+
979+ Example 1 ::
908980
909981 ## 2D system
910982
@@ -917,7 +989,7 @@ def derivs6(x,t):
917989 y0 = (1,2)
918990 yout = rk4(derivs6, y0, t)
919991
920- Example 2:
992+ Example 2::
921993
922994 ## 1D system
923995 alpha = 2
@@ -963,7 +1035,7 @@ def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
9631035 """
9641036 Bivariate gaussan distribution for equal shape X, Y
9651037
966- http://mathworld.wolfram.com/BivariateNormalDistribution.html
1038+ See `bivariate normal < http://mathworld.wolfram.com/BivariateNormalDistribution.html>`_ at mathworld.
9671039 """
9681040 Xmu = X - mux
9691041 Ymu = Y - muy
@@ -1074,13 +1146,16 @@ def liaupunov(x, fprime):
10741146 *x* is a very long trajectory from a map, and *fprime* returns the
10751147 derivative of *x*.
10761148
1077- Returns :math:`\lambda = \f rac{1}{n}\sum \ln|f^'(x_i)|`
1149+ Returns :
1150+ .. math::
1151+
1152+ \lambda = \f rac{1}{n}\sum \ln|f^'(x_i)|
10781153
10791154 .. seealso::
10801155 Sec 10.5 Strogatz (1994) "Nonlinear Dynamics and Chaos".
10811156
10821157 `Wikipedia article on Lyapunov Exponent
1083- http://en.wikipedia.org/wiki/Lyapunov_exponent`_.
1158+ < http://en.wikipedia.org/wiki/Lyapunov_exponent> `_.
10841159
10851160 .. note::
10861161 What the function here calculates may not be what you really want;
@@ -1510,13 +1585,14 @@ def diagonal_matrix(diag):
15101585 return np .diag (diag )
15111586
15121587def identity (n , rank = 2 , dtype = 'l' , typecode = None ):
1513- """identity(n,r) returns the identity matrix of shape (n,n,...,n) (rank r).
1588+ """Returns the identity matrix of shape (n,n,...,n) (rank r).
15141589
15151590 For ranks higher than 2, this object is simply a multi-index Kronecker
1516- delta:
1517- / 1 if i0=i1=...=iR,
1518- id[i0,i1,...,iR] = -|
1519- \ 0 otherwise.
1591+ delta::
1592+
1593+ / 1 if i0=i1=...=iR,
1594+ id[i0,i1,...,iR] = -|
1595+ \ 0 otherwise.
15201596
15211597 Optionally a dtype (or typecode) may be given (it defaults to 'l').
15221598
0 commit comments