# HG changeset patch # User Puneeth Chaganti # Date 1286777404 -19800 # Node ID 7c4855fb8e5f7a8b63ea606cdce84d9fd968f795 # Parent 55342d3c9d25e060a706cac9ffbbb8857e15e363 Quickrefs diff -r 55342d3c9d25 -r 7c4855fb8e5f accessing-pieces-arrays/quickref.tex --- a/accessing-pieces-arrays/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/accessing-pieces-arrays/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Accessing parts of arrays} + +\lstinline|C[i-1, j-1]| to access element i, j in C (mxn). +\lstinline|C[i-1]| to access i^{th} row +\lstinline|C[:, j-1]| to access j^{th} column -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +Assigning to accessed elements, changes them. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|A[m:n:o]| accesses the rows from \lstinline|m| +to \lstinline|n| (excluded) in steps of \lstinline|o| + +Similarly, \lstinline|C[m:n:o, p:q:r]| diff -r 55342d3c9d25 -r 7c4855fb8e5f advanced-features-functions/quickref.tex --- a/advanced-features-functions/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/advanced-features-functions/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,8 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Advanced features of functions} + +Arguments of functions can have default arguments. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +All arguments with default arguments are at the end of the definition. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +Functions can be called with keyword arguments. All the keyword +arguments should be at the end of the argument list. diff -r 55342d3c9d25 -r 7c4855fb8e5f getting-started-files/quickref.tex --- a/getting-started-files/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/getting-started-files/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting Started -- files} + +\lstinline|f = open('filename')| returns a file object. \lstinline|f| +can be used to perform further operations on the file. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|f.read()| reads the whole file and returns the contents. + +\lstinline|f.close()| closes the file. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|for line in open('filename'):| -- iterate over the file +line-by-line. + diff -r 55342d3c9d25 -r 7c4855fb8e5f getting-started-ipython/quickref.tex --- a/getting-started-ipython/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/getting-started-ipython/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting started -- \texttt{ipython}} + +To start \lstinline|ipython| with \lstinline|pylab|:\\ +\lstinline| $ ipython -pylab| %$ + +To exit: \lstinline|^D| (Ctrl-D) -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +To interrupt: \lstinline|^C| (Ctrl-C) + +Tab completes partial commands -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\texttt{?} to look up documentation. + +Arrow keys to navigate the history. diff -r 55342d3c9d25 -r 7c4855fb8e5f loading-data-from-files/quickref.tex --- a/loading-data-from-files/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/loading-data-from-files/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Loading data from files} + +\lstinline|loadtxt('filename')| returns the columns of file in one +sequence. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|x, y = loadtxt('filename', unpack=True)| to obtain a file +with 2 columns in separate sequences. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|loadtxt('filename', delimiter=';')|, if the file has +columns separated by ';' instead of spaces/tabs. + + diff -r 55342d3c9d25 -r 7c4855fb8e5f loops/quickref.tex --- a/loops/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/loops/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,16 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{loops} + +To iterate over a sequence: \lstinline|for i in sequence:|\\ +\texttt{i} is the looping variable. + +To iterate while a condition is true: \lstinline|while condition:| -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +Blocks in python are indented. To end block return to the previous +indentation. + +To break out of the innermost loop: \lstinline|break| -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +To skip to end of current iteration: \lstinline|continue| + +\lstinline|pass| is just a syntactic filler. + diff -r 55342d3c9d25 -r 7c4855fb8e5f manipulating-strings/quickref.tex --- a/manipulating-strings/quickref.tex Mon Oct 11 01:25:45 2010 +0530 +++ b/manipulating-strings/quickref.tex Mon Oct 11 11:40:04 2010 +0530 @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Manipulating strings} + +String indexing starts from 0, like lists. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|s = `Hello World'|\\ +\lstinline|s[0:5]| gives \texttt{Hello}\\ +\lstinline|s[6:]| gives \textt{World}\\ +\lstinline|s[6::2]| gives \textt{Wrd}\\ -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|s.replace('e', 'a')| returns a new string with all e's +replaced by a. + +\lstinline|s.lower()| and \lstinline|s.upper()| return new strings +with all lower and upper case letters, respectively.