diff options
author | Puneeth Chaganti | 2010-10-11 11:40:04 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-10-11 11:40:04 +0530 |
commit | 98aafc8888970c0dc6da22cfb057c103334065ed (patch) | |
tree | e5e1b2b8f0255a378f8202668bc182592c4dc1f4 | |
parent | f09d82f3c8f5a84ece5a42412e31cf1c71b89ea9 (diff) | |
download | st-scripts-98aafc8888970c0dc6da22cfb057c103334065ed.tar.gz st-scripts-98aafc8888970c0dc6da22cfb057c103334065ed.tar.bz2 st-scripts-98aafc8888970c0dc6da22cfb057c103334065ed.zip |
Quickrefs
-rw-r--r-- | accessing-pieces-arrays/quickref.tex | 16 | ||||
-rw-r--r-- | advanced-features-functions/quickref.tex | 12 | ||||
-rw-r--r-- | getting-started-files/quickref.tex | 16 | ||||
-rw-r--r-- | getting-started-ipython/quickref.tex | 18 | ||||
-rw-r--r-- | loading-data-from-files/quickref.tex | 16 | ||||
-rw-r--r-- | loops/quickref.tex | 20 | ||||
-rw-r--r-- | manipulating-strings/quickref.tex | 18 |
7 files changed, 74 insertions, 42 deletions
diff --git a/accessing-pieces-arrays/quickref.tex b/accessing-pieces-arrays/quickref.tex index b26d168..6226b91 100644 --- a/accessing-pieces-arrays/quickref.tex +++ b/accessing-pieces-arrays/quickref.tex @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Accessing parts of arrays} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\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 lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +Assigning to accessed elements, changes them. + +\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 --git a/advanced-features-functions/quickref.tex b/advanced-features-functions/quickref.tex index b26d168..160370e 100644 --- a/advanced-features-functions/quickref.tex +++ b/advanced-features-functions/quickref.tex @@ -1,8 +1,8 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Advanced features of functions} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +Arguments of functions can have default arguments. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +All arguments with default arguments are at the end of the definition. + +Functions can be called with keyword arguments. All the keyword +arguments should be at the end of the argument list. diff --git a/getting-started-files/quickref.tex b/getting-started-files/quickref.tex index b26d168..17b4d33 100644 --- a/getting-started-files/quickref.tex +++ b/getting-started-files/quickref.tex @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting Started -- files} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|f = open('filename')| returns a file object. \lstinline|f| +can be used to perform further operations on the file. + +\lstinline|f.read()| reads the whole file and returns the contents. + +\lstinline|f.close()| closes the file. + +\lstinline|for line in open('filename'):| -- iterate over the file +line-by-line. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/getting-started-ipython/quickref.tex b/getting-started-ipython/quickref.tex index b26d168..460b921 100644 --- a/getting-started-ipython/quickref.tex +++ b/getting-started-ipython/quickref.tex @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting started -- \texttt{ipython}} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +To start \lstinline|ipython| with \lstinline|pylab|:\\ +\lstinline| $ ipython -pylab| %$ -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +To exit: \lstinline|^D| (Ctrl-D) + +To interrupt: \lstinline|^C| (Ctrl-C) + +Tab completes partial commands + +\texttt{?} to look up documentation. + +Arrow keys to navigate the history. diff --git a/loading-data-from-files/quickref.tex b/loading-data-from-files/quickref.tex index b26d168..c3bbe95 100644 --- a/loading-data-from-files/quickref.tex +++ b/loading-data-from-files/quickref.tex @@ -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. + +\lstinline|x, y = loadtxt('filename', unpack=True)| to obtain a file +with 2 columns in separate sequences. + +\lstinline|loadtxt('filename', delimiter=';')|, if the file has +columns separated by ';' instead of spaces/tabs. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/loops/quickref.tex b/loops/quickref.tex index b26d168..e0b8d61 100644 --- a/loops/quickref.tex +++ b/loops/quickref.tex @@ -1,8 +1,16 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{loops} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +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:| + +Blocks in python are indented. To end block return to the previous +indentation. + +To break out of the innermost loop: \lstinline|break| + +To skip to end of current iteration: \lstinline|continue| + +\lstinline|pass| is just a syntactic filler. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/manipulating-strings/quickref.tex b/manipulating-strings/quickref.tex index b26d168..533a1ef 100644 --- a/manipulating-strings/quickref.tex +++ b/manipulating-strings/quickref.tex @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Manipulating strings} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +String indexing starts from 0, like lists. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|s = `Hello World'|\\ +\lstinline|s[0:5]| gives \texttt{Hello}\\ +\lstinline|s[6:]| gives \textt{World}\\ +\lstinline|s[6::2]| gives \textt{Wrd}\\ + +\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. |