On Thu, 22 Nov 2007, Rich Shepard wrote: >> For parsimony, I think you're probably best off just using the >> Gaussian equation: >> >> def fwhm2k(fwhm): >> '''converts fwhm value to k (see above)''' >> return fwhm/(2 * n.sqrt( n.log( 2 ) ) ) >> >> def gauss1d(r, fwhm, c): >> '''returns the 1d gaussian given by fwhm (full-width at half-max), >> and c (centre) at positions given by r >> ''' >> return exp( -(r-c)**2 / fwhm2k( fwhm )**2 ) > > Thank you, Angus. I'll look at the Gaussian explanation to understand the > input values.
It's been decades since I've needed to write any statistical or distributional function code; I used SysStat in DOS for quite some time and R for the past decade with linux. There's a great difference between using working code and writing one's one code. :-) Looking more carefully at the SciPy stats module, I see the normal distribution is included as a class. However, I don't understand all the functions in that class -- other than normal.pdf(x) -- and do not see where loc and scale (representing mean and std. deviation) are used. Toward understanding how to use this code to draw the curves I need, I extracted the one method into a stand-alone file and tried to plot a Normal/Bell curve from 0 to 100: import matplotlib.numerix as nx import pylab as p from math import * def normal(x): return exp(-x**2.0/2.0)/sqrt(2.0*pi) x = nx.arange(0, 100, 0.1) N = normal(x) p.plot(x, N, color='red', lw=2) p.axis([0, 100, 0.0, 1.0]) p.xlabel('Universe of Discourse') p.ylabel('Membership Grade') p.show() The error returned is: Traceback (most recent call last): File "normal-curve.py", line 17, in ? N = normal(x) File "normal-curve.py", line 14, in normal return exp(-x**2.0/2.0)/sqrt(2.0*pi) TypeError: only length-1 arrays can be converted to Python scalars A clue stick to the meaning of this error message, and how to fix the problem is needed. Rich -- Richard B. Shepard, Ph.D. | Integrity Credibility Applied Ecosystem Services, Inc. | Innovation <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users