Quickrefs
authorPuneeth Chaganti <punchagan@fossee.in>
Mon, 11 Oct 2010 11:40:04 +0530
changeset 285 7c4855fb8e5f
parent 284 55342d3c9d25
child 286 44f06ae0d957
Quickrefs
accessing-pieces-arrays/quickref.tex
advanced-features-functions/quickref.tex
getting-started-files/quickref.tex
getting-started-ipython/quickref.tex
loading-data-from-files/quickref.tex
loops/quickref.tex
manipulating-strings/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]|
--- 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. 
--- 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. 
+
--- 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. 
--- 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. 
+
+
--- 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. 
+
--- 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.