From: <fer...@us...> - 2007-12-03 08:22:18
|
Revision: 4556 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4556&view=rev Author: fer_perez Date: 2007-12-03 00:22:16 -0800 (Mon, 03 Dec 2007) Log Message: ----------- Reorganize a bit. Waste 2 hours dealing with utf-8 problems with latex... Modified Paths: -------------- trunk/py4science/workbook/intro_to_python.tex trunk/py4science/workbook/ipython_tut.tex trunk/py4science/workbook/main.tex trunk/py4science/workbook/matplotlib_tut.tex trunk/py4science/workbook/qsort.tex trunk/py4science/workbook/why_python.tex trunk/py4science/workbook/wrapping.tex Added Paths: ----------- trunk/py4science/workbook/introduction.tex Modified: trunk/py4science/workbook/intro_to_python.tex =================================================================== --- trunk/py4science/workbook/intro_to_python.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/intro_to_python.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -734,13 +734,12 @@ \end{lyxcode} -There are two string methods, \texttt{split} and \texttt{join}, that -arise frequenctly in Numeric processing, specifically in the context -of processing data files that have comma, tab, or space separated -numbers in them. \texttt{split} takes a single string, and splits -it on the indicated character to a sequence of strings. This is useful -to take a single line of space or comma separated values and split -them into individual numbers +There are two string methods, \texttt{split} and \texttt{join}, that arise +frequenctly in numerical processing, specifically in the context of processing +data files that have comma, tab, or space separated numbers in +them. \texttt{split} takes a single string, and splits it on the indicated +character to a sequence of strings. This is useful to take a single line of +space or comma separated values and split them into individual numbers \begin{lyxcode} \textcolor{blue}{\#~s~is~a~single~string~and~we~split~it~into~a~list~of~strings} Added: trunk/py4science/workbook/introduction.tex =================================================================== --- trunk/py4science/workbook/introduction.tex (rev 0) +++ trunk/py4science/workbook/introduction.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -0,0 +1,41 @@ +\chapter*{Introduction} + +This book is currently a work in progress, and ultimately we hope it will +evolve into an open, community-driven document developed in tandem with the +underlying tools, by the same scientists who have written them. + +The book is aimed at practicing scientists, students and in general anyone who +is looking for a modern, high-level and open platform for scientific +computing. The Python language is in the opinion of the authors the leading +candidate today for this role. + +The book is broadly divided in two parts: the first is a general discussion of +the Python tools used for scientific work, with an explanatory approach. It is +not a complete Python reference book, as there are many excellent resources for +the base language, both in print and online. But beyond the basic language and +the NumPy book, it should serve as reasonably self-contained description of the +core libraries for common numerical tasks. + +The second part is meant as a practical workbook, and the build system used to +produce the document will in the future allow users to create custom versions +with only the examples that they deem practical for any given audience. This +workbook approach grew out of a sequence of workshops taught by the editors at +a number of research institutions and universities, and we've found it to be +extremely convenient. + +The workbook is structured as a collection of problems, meant to be solved by +the reader as programming exercises. The entire book can be compiled in one of +two forms: either with the examples in `skeleton' form, where they contain +incomplete code meant to be filled in, or with the full solution code. This +should enable instructors to hand out the skeleton workbook at courses and +workshops, with the solutions being available as well for after the teaching is +over. + +We hope that the community will continue to contribute many more examples, so +that ultimately the projects allows for the easy construction of custom +workbooks tailored to the needs of different audiences. + +\begin{flushright} +John D. Hunter and Fernando P\xE9rez, editors. + +\end{flushright} Modified: trunk/py4science/workbook/ipython_tut.tex =================================================================== --- trunk/py4science/workbook/ipython_tut.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/ipython_tut.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -1020,8 +1020,6 @@ \item \texttt{\$HOME/.ipython/ipythonrc}: load basic things you always want. \item \texttt{\$HOME/.ipython/ipythonrc-math}: load (1) and basic math-related modules. -\item \texttt{\$HOME/.ipython/ipythonrc-numeric}: load (1) and Numeric and -plotting modules. \end{enumerate} Since it is possible to create an endless loop by having circular file inclusions, IPython will stop if it reaches 15 recursive inclusions. Modified: trunk/py4science/workbook/main.tex =================================================================== --- trunk/py4science/workbook/main.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/main.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -45,6 +45,9 @@ \usepackage{babel} \makeatother + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Begin main document - front matter + \begin{document} \title{ \vspace{3cm} @@ -67,10 +70,15 @@ \tableofcontents{} -\part{Discussion} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Main document - body +\input{introduction.tex} + +\part{General Discussion} + % In this part, each tex file is a chapter by itself, since it is more or less % meant to be used in whole. + \input{why_python.tex} \input{intro_to_python.tex} @@ -83,7 +91,8 @@ -\part{Workbook} +\part{Workbook\\ +A Problem Collection} % This part specifies the chapter declarations in the main file, while the % chapters are made of individual TeX files which themselves should be written @@ -91,26 +100,19 @@ % few closely related topics, and to allow users to build them with as many or % as few actual sections as desired for a given audience. -\chapter{Introduction} - +\chapter{Introduction to the workbook} \input{intro.tex} -\chapter{Simple non-numerical problems} - +\chapter{Simple non-numerical Problems} \input{qsort.tex} - \input{wordfreqs.tex} \chapter{Working with files, the internet, and numpy arrays} - \input{files_etc.tex} -\chapter{Elementary Numerics} - +\chapter{Elementary numerics} \input{wallis_pi.tex} - \input{trapezoid.tex} - \input{quad_newton.tex} \chapter{Linear algebra} @@ -122,7 +124,7 @@ \input{convolution.tex} \input{fft_imdenoise.tex} -\chapter{Dynamical Systems} +\chapter{Dynamical systems} \input{intro_dynsys.tex} \input{lotka_volterra.tex} @@ -131,9 +133,11 @@ \input{stats_descriptives.tex} \input{stats_distributions.tex} -\chapter{Plotting on Maps} +\chapter{Plotting on maps} \input{basemap.tex} +%%% Bibliography section + \bibliographystyle{plain} \bibliography{python,python2} Modified: trunk/py4science/workbook/matplotlib_tut.tex =================================================================== --- trunk/py4science/workbook/matplotlib_tut.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/matplotlib_tut.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -6,17 +6,16 @@ matplotlib is a library for making 2D plots of arrays in python.% \footnote{This short guide is not meant as a complete guide or tutorial. There -is a more comprehensive user's guide and tutorial on the matplotlib -web-site at http://matplotlib.sf.net.% -} Although it has its origins in emulating the Matlab graphics commands, -it does not require matlab, and has a pure, object oriented API. Although -matplotlib is written primarily in python, it makes heavy use of Numeric/numarray -and other extension code to provide good performance even for large -arrays. matplotlib is designed with the philosophy that you should -be able to create simple plots with just a few commands, or just one! -If you want to see a histogram of your data, you shouldn't need to -instantiate objects, call methods, set properties, and so on; it should -just work. + is a more comprehensive user's guide and tutorial on the matplotlib web-site + at http://matplotlib.sf.net.% +} Although it has its origins in emulating the Matlab graphics commands, it +does not require matlab, and has a pure, object oriented API. Although +matplotlib is written primarily in python, it makes heavy use of NumPy and +other extension code to provide good performance even for large +arrays. matplotlib is designed with the philosophy that you should be able to +create simple plots with just a few commands, or just one! If you want to see +a histogram of your data, you shouldn't need to instantiate objects, call +methods, set properties, and so on; it should just work. The matplotlib code is divided into three parts: the \textit{pylab interface} is the set of functions provided by the \texttt{pylab} @@ -355,68 +354,7 @@ In~{[}25]:~set(t,~fontsize=20,~color='darkslategray')~ \end{lyxcode} -\section[numerix]{A common interface to Numeric and numarray} -Currently the python computing community is in a state of having too -many array pacakges, none of which satisfy everyone's needs. Although -Numeric and numarray both provide the same set of core functions, -they are organized differently, and matplotlib provides a compatibility -later so you can use either one in your matplotlib scripts without -having to change your code. - -Several numarray/Numeric developers are codevelopers of matplotlib, -giving matplotlib full Numeric and numarray compatibility, thanks -in large part to Todd Miller's \texttt{matplotlib.numerix} module -and the numarray compatibility layer for extension code. This allows -you to choose between Numeric or numarray at the prompt or in a config -file. Thus when you do - -\begin{lyxcode} -\textcolor{blue}{\#~import~matplotlib~and~all~the~numerix~functions} - -from~pylab~import~{*} -\end{lyxcode} -you'll not only get all the matplotlib pylab interface commands, but -most of the Numeric or numarray package as well (depending on your -\texttt{numerix} setting). All of the array creation and manipulation -functions are imported, such as \texttt{array}, \texttt{arange}, \texttt{take}, -\texttt{where}, etc, as are the external module functions which reside -in \texttt{mlab, fft} and \texttt{linear\_algebra.} - -Even if you don't want to import all of the numerix symbols from the -pytlab interface, to make your matplotlib scripts as portable as possible -with respect to your choice of array packages, it is advised not to -explicitly import Numeric or numarray. Rather, you should use \texttt{matplotlib.numerix} -where possible, either by using the functions imported by \texttt{pylab}, -or by explicitly importing the \texttt{numerix} module, as in - -\begin{lyxcode} -\textcolor{blue}{\#~create~a~numerix~namespace} - -import~matplotlib.numerix~as~n - -from~matplotlib.numerix.mlab~import~mean - -x~=~n.arange(100) - -y~=~n.take(x,~range(10,20)) - -print~mean(y) -\end{lyxcode} -For the remainder of this manual, the term \texttt{numerix} is used -to mean either the Numeric or numarray package. To select numarray -or Numeric from the prompt, run your matplotlib script with - -\begin{lyxcode} -~~>~python~myscript.py~-{}-numarray~~\textcolor{blue}{\#~use~numarray} - -~~>~python~myscript.py~-{}-Numeric~~~\textcolor{blue}{\#~use~Numeric} -\end{lyxcode} -Typically, however, users will choose one or the other and make this -setting in their rc file using either \texttt{numerix : Numeric} or -\texttt{numerix : numarray}. - - \section[matplotlibrc]{Customizing the default behavior with the rc file} matplotlib is designed to work in a variety of settings: some people @@ -436,13 +374,13 @@ \begin{lyxcode} C:\textbackslash{}Python23\textbackslash{}share\textbackslash{}matplotlib\textbackslash{}.matplotlibrc~\textcolor{blue}{\#~windows}~/usr/share/matplotlib/.matplotlibrc~~\textcolor{blue}{\#~linux} \end{lyxcode} -By default, the installer will overwrite the existing file in the -install path, so if you want to preserve your's, please move it to -your \texttt{HOME} dir and set the environment variable if necessary. -In the rc file, you can set your backend , your numerix setting , -whether you'll be working interactively and default values for most -of the figure properties. +By default, the installer will overwrite the existing file in the install path, +so if you want to preserve yours, please move it to your \texttt{HOME} dir and +set the environment variable if necessary. In the rc file, you can set your +backend, whether you'll be working interactively and default values for most of +the figure properties. + In the RC file, blank lines, or lines starting with a comment symbol, are ignored, as are trailing comments. Other lines must have the format Modified: trunk/py4science/workbook/qsort.tex =================================================================== --- trunk/py4science/workbook/qsort.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/qsort.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -30,12 +30,16 @@ \subsection*{Hints} \begin{itemize} -\item Python has no particular syntactic requirements for implementing recursion, -but it does have a maximum recursion depth. This value can be queried -via the function \texttt{sys.getrecursionlimit()}, and it can be changed -with \texttt{sys.setrecursionlimit(new\_value)}. + +\item Python has no particular syntactic requirements for implementing + recursion, but it does have a maximum recursion depth. This value can be + queried via the function \texttt{sys.getrecursionlimit()}, and it can be + changed with \texttt{sys.setrecursionlimit(new\_value)}. + \item Like in all recursive problems, don't forget to implement an exit -condition! + condition! + \item If \texttt{L} is a list, the call \texttt{len(L)} provides its length. + \end{itemize} Modified: trunk/py4science/workbook/why_python.tex =================================================================== --- trunk/py4science/workbook/why_python.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/why_python.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -43,7 +43,7 @@ group at the Scripps Research Institute uses Python extensively to build a suite of applications for molecular visualization and exploration of drug/molecule interactions using virtual reality and 3D printing -technology\cite{Sanner2005a,Sanner2005b}. Engineers at Google use +technology \cite{Sanner2005a,Sanner2005b}. Engineers at Google use Python in automation, control and tuning of their computational grid, and use \texttt{SWIG} generated Python of their in-house C++ libraries in virtually all facets of their work \cite{Beazley1998,Stein2005}. @@ -116,7 +116,7 @@ Complementing these built-in features, Python is also readily extensible, giving it a wealth of libraries for scientific computing that have been in development for many years \cite{Dubois1996b,Dubois1996c}. -\texttt{Numeric Python} supports large array manipulations, math, +\texttt{NumPy} supports large array manipulations, math, optimized linear algebra, efficient Fourier transforms and random numbers. \texttt{scipy} is a collection of Python wrappers of high performance FORTRAN code (eg LAPACK, ODEPACK) for numerical analysis @@ -239,8 +239,8 @@ 256x256 pixels, and each pixel is a 2 byte integer. We read this into a string using python's \texttt{file} function -- the 'rb' flag says to open the file in \texttt{read/binary} mode. We can then use the -numerix \texttt{fromstring} method to convert this to an array, passing -the type of the data (\texttt{Int16}) as an argument. We reshape the +numpy \texttt{fromstring} method to convert this to an array, passing +the type of the data (\texttt{int16}) as an argument. We reshape the array by changing the array shape attribute to 256 by 256, and pass this off to the matplotlib pylab command \texttt{imshow} for plotting. matplotlib has a number of colormaps, and the default one is jet; @@ -277,7 +277,7 @@ \end{lyxcode} creates a 20x30 array of zeros (default integer type; details on how to specify other types will follow). Note that the dimensions ({}``shape'' -in numarray parlance) are specified by giving the dimensions as a +in numpy parlance) are specified by giving the dimensions as a comma-separated list within parentheses. The parentheses aren't necessary for a single dimension. As an aside, the parentheses used this way are being used to specify a Python tuple; more will be said about @@ -333,36 +333,35 @@ \subsection{Array numeric types} -numarray supports all standard numeric types. The default integer +numpy supports all standard numeric types. The default integer matches what Python uses for integers, usually 32 bit integers or -what numarray calls \texttt{Int32}. The same is true for floats, i.e., -generally 64-bit doubles called \texttt{Float64} in numarray. The -default complex type is \texttt{Complex64}. Many of the functions +what numpy calls \texttt{int32}. The same is true for floats, i.e., +generally 64-bit doubles called \texttt{float64} in numpy. The +default complex type is \texttt{complex64}. Many of the functions accept a type argument. For example \begin{lyxcode} ->\,{}>\,{}>~zeros(3,~Int8)~\#~Signed~byte +>\,{}>\,{}>~zeros(3,~int8)~\#~Signed~byte ->\,{}>\,{}>~zeros(3,~type=UInt8)~\#~Unsigned~byte +>\,{}>\,{}>~zeros(3,~dtype=uint8)~\#~Unsigned~byte ->\,{}>\,{}>~array({[}2,3],~type=Float32) +>\,{}>\,{}>~array({[}2,3],~dtype=float32) ->\,{}>\,{}>~arange(4,~type=Complex64) +>\,{}>\,{}>~arange(4,~dtype=complex64) \end{lyxcode} -The possible types are \texttt{Int8, UInt8, Int16, UInt16, Int32, -UInt32, Int64, UInt64, Float32, Float64, Complex32, Complex64.} To -find out the type of an array use the .type() method. E.g., +The possible types are \texttt{int8, uint8, int16, uint16, int32, +uint32, int64, uint64, float32, float64, complex32, complex64.} To +find out the type of an array use the .dtype() method. E.g., \begin{lyxcode} ->\,{}>\,{}>~arr.type() - -Float32 +>\,{}>\,{}>~arr.dtype() +dtype('float32') \end{lyxcode} To convert an array to a different type use the \texttt{astype()} method, e.g, \begin{lyxcode} ->\,{}>\,{}>~a~=~arr.astype(Float64) +>\,{}>\,{}>~a~=~arr.astype(float64) \end{lyxcode} \subsection{Printing arrays} @@ -537,7 +536,7 @@ All of the indexing tools available for 1-D arrays apply to \emph{n}-dimensional arrays as well (though combining index arrays with slices is not currently permitted). To understand all the indexing options in their full detail, -read sections 4.6, 4.7 and 6 of the numarray manual. +read sections 4.6, 4.7 and 6 of the numpy manual. \subsection{Compatibility of dimensions} @@ -711,7 +710,7 @@ \subsection{Array functions} There are many array utility functions. The following lists the more -useful ones with a one line description. See the numarray manual for +useful ones with a one line description. See the numpy manual for details on how they are used. Arguments shown with argument=value indicate what the default value is if called without a value for that argument. @@ -858,9 +857,7 @@ \item [{\texttt{\emph{a}}\texttt{.repeat}\textmd{(a,repeats,axis=0):}}]~ \item [{\texttt{\emph{a}}\texttt{.resize}\textmd{(shape):}}]~ \item [{\texttt{\emph{a}}\texttt{.size}\textmd{():}}] same as nelements -\item [{\texttt{\emph{a}}\texttt{.type}\textmd{():}}] returns type of array -\item [{\texttt{\emph{a}}\texttt{.typecode}\textmd{():}}] returns corresponding -typecode character used by Numeric +\item [{\texttt{\emph{a}}\texttt{.dtype}\textmd{():}}] returns type of array \item [{\texttt{\emph{a}}\texttt{.tofile}\textmd{(}\textmd{\emph{file}}\textmd{):}}] write binary data to file \item [{\texttt{\emph{a}}\texttt{.tolist}\textmd{():}}] convert data to Modified: trunk/py4science/workbook/wrapping.tex =================================================================== --- trunk/py4science/workbook/wrapping.tex 2007-12-03 04:56:57 UTC (rev 4555) +++ trunk/py4science/workbook/wrapping.tex 2007-12-03 08:22:16 UTC (rev 4556) @@ -125,8 +125,8 @@ causes f2py to keep cached copies of the scratch areas, so no unnecessary mallocs should be triggered. -Since f2py relies on Numeric arrays, all dimensions can be determined -from the arrays themselves and it is not necessary to pass them explicitly. +Since f2py relies on NumPy arrays, all dimensions can be determined from the +arrays themselves and it is not necessary to pass them explicitly. With all this, the resulting f2py-generated docstring becomes: @@ -232,7 +232,7 @@ \subsection{Passing offset arrays to Fortran routines} It is possible to pass offset arrays (like pointers to the middle -of other arrays) by using Numeric's slice notation. +of other arrays) by using NumPy's slice notation. The print\_dvec function below simply prints its argument as \char`\"{}print{*},'x',x\char`\"{}. We show some examples of how it behaves with both 1 and 2-d arrays: @@ -339,7 +339,7 @@ \subsection{On matrix ordering and in-memory copies} -Numeric (which f2py relies on) is C-based, and therefore its arrays +NumPy (which f2py relies on) is C-based, and therefore its arrays are stored in row-major order. Fortran stores its arrays in column-major order. This means that copying issues must be dealt with. Below we reproduce some comments from Pearu on this topic given in the f2py @@ -348,7 +348,7 @@ \begin{quote} To avoid copying, you should create array that has internally Fortran data ordering. This is achived, for example, by reading/creating your -data in Fortran ordering to Numeric array and then doing Numeric.transpose +data in Fortran ordering to NumPy array and then doing numpy.transpose on that. Every f2py generated extension module provides also function has\_column\_major\_storage @@ -360,7 +360,7 @@ Also note that copying done by f2py generated interface is carried out in C on the raw data and therefore it is extremely fast compared -to if you would make a copy in Python, even when using Numeric. Tests +to if you would make a copy in Python, even when using NumPy. Tests with say 1000x1000 matrices show that there is no noticable performance hit when copying is carried out, in fact, sometimes making a copy may speed up things a bit -- I was quite surprised about that myself. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |