summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantosh G. Vattam2009-10-28 20:33:27 +0530
committerSantosh G. Vattam2009-10-28 20:33:27 +0530
commitb539df1abd7f166096e290ab9cdcc93980928e63 (patch)
tree4ce109aac78fffbbc371fc4521d1e2f7cd897ab4
parent411c161724ab44b464057cf4ff897876a54d587f (diff)
parent6ee4cc71412e1254bbdc9a1db9819ce464e5aff1 (diff)
downloadworkshops-more-scipy-b539df1abd7f166096e290ab9cdcc93980928e63.tar.gz
workshops-more-scipy-b539df1abd7f166096e290ab9cdcc93980928e63.tar.bz2
workshops-more-scipy-b539df1abd7f166096e290ab9cdcc93980928e63.zip
Merged branches.
-rw-r--r--day1/session1.tex56
-rw-r--r--day1/session3.tex130
-rw-r--r--day1/sslc1.py50
-rw-r--r--day2/session1.tex68
-rw-r--r--day2/session2.tex6
5 files changed, 225 insertions, 85 deletions
diff --git a/day1/session1.tex b/day1/session1.tex
index 1a5d8ca..85a8f48 100644
--- a/day1/session1.tex
+++ b/day1/session1.tex
@@ -159,27 +159,23 @@
\end{itemize}
\end{block}
- \begin{block}{Goal}
- Successful participants will be able to
- \begin{itemize}
- \item use Python as their scripting and problem solving language.
- \item train the students to use Python for the same
- \end{itemize}
+ \begin{block}{Goal: Successful participants will be able to}
+ \begin{itemize}
+ \item Use Python as plotting, computational toolkit
+ \item Understand how Python can be used as scripting and problem solving language.
+ \item Train the students to use Python for the same
+ \end{itemize}
\end{block}
\end{frame}
-
+\section{Getting started}
\begin{frame}
-\frametitle{Bucketlist}
- \begin{block}{IPython}
- Type ipython at the command line. Is it available?
- \end{block}
- \begin{block}{Editor}
- We recommend scite.
- \end{block}
- \begin{block}{Data files}
- Make sure you have all data files.
- \end{block}
+\frametitle{Checklist}
+ \begin{enumerate}
+ \item IPython: Type ipython at the command line. Is it available?
+ \item Editor: We recommend scite.
+ \item Data files: Make sure you have all data files.
+ \end{enumerate}
\end{frame}
\begin{frame}[fragile]
@@ -215,6 +211,9 @@ Breaking out of loops
\end{lstlisting}
\end{frame}
+\section{Plotting}
+
+\subsection{Drawing plots}
\begin{frame}[fragile]
\frametitle{First Plot}
\begin{columns}
@@ -249,6 +248,7 @@ plots \typ{x} and \typ{y} using default line style and color
\end{block}
\end{frame}
+\subsection{Decoration}
\begin{frame}[fragile]
\frametitle{Adding Labels}
\begin{columns}
@@ -287,6 +287,7 @@ In []: ylabel('sin(2y)')
\emphbar{By default plots would be overlaid!}
\end{frame}
+\subsection{More decoration}
\begin{frame}[fragile]
\frametitle{Title and Legends}
\vspace*{-0.15in}
@@ -358,6 +359,7 @@ In []: close()
\end{lstlisting}
\end{frame}
+\section{Multiple plots}
\begin{frame}[fragile]
\frametitle{Plotting separate figures}
\begin{lstlisting}
@@ -433,6 +435,7 @@ In []: plot(x, -x, 'b')
$\vdots$
\end{frame}
+\section{Exercises}
\begin{frame}[fragile]
\frametitle{Review Problem \ldots}
\small{
@@ -454,19 +457,16 @@ In []: ylim(5*pi, 5*pi)
}
\end{frame}
\begin{frame}
- \frametitle{Things we have learned}
+ \frametitle{What did we learn?}
\begin{itemize}
- \item Creating simple plots.
- \item Adding labels and legends.
- \item Annotating plots.
- \item Changing the looks: size, linewidth
+ \item Creating simple plots.
+ \item Adding labels and legends.
+ \item Annotating plots.
+ \item Changing the looks: size, linewidth
\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
- \begin{center}
- End of Session-1\\
- \alert{Don't Close \typ{IPython}}
- \end{center}
+ \begin{block}{Note}
+ \centerline{\alert{Don't Close \typ{IPython}}}
+ \end{block}
\end{frame}
\end{document}
diff --git a/day1/session3.tex b/day1/session3.tex
index 435789c..7019a7c 100644
--- a/day1/session3.tex
+++ b/day1/session3.tex
@@ -126,7 +126,7 @@
%% % You might wish to add the option [pausesections]
%% \end{frame}
-\section{Statistics}
+\section{Processing voluminous data}
\begin{frame}
\frametitle{More on data processing}
\begin{block}{}
@@ -136,13 +136,31 @@
\begin{frame}
- \frametitle{Statistical Analysis and Parsing}
- Read the data supplied in \emph{sslc1.txt} and obtain the following statistics:
- \begin{itemize}
- \item Draw a pie chart representing the number of students who scored more than 90\% in Science per region.
- \item Draw a pie chart representing the number of students who scored more than 90\% per subject(All regions combined).
+ \frametitle{Statistical Analysis: Problem statement}
+ Read the data supplied in \emph{sslc1.txt} and carry out the following:
+ \begin{enumerate}
+ \item Draw a pie chart representing the proportion of students who scored more than 90\% in each region in Science.
+ \item Draw a pie chart representing the proportion of students who scored more than 90\% in each subject across regions.
\item Print mean, median, mode and standard deviation of math scores for all regions combined.
- \end{itemize}
+ \end{enumerate}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Problem statement: explanation}
+ \emphbar{Draw a pie chart representing the proportion of students who scored more than 90\% in each region in Science.}
+ \begin{enumerate}
+ \item Complete(100\%) data - Number of students who scored more than 90\% in Science
+ \item Each slice - Number of students who scored more than 90\% in Science in one region
+ \end{enumerate}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Problem statement: explanation}
+ \emphbar{Draw a pie chart representing the proportion of students who scored more than 90\% in each subject across regions.}
+ \begin{enumerate}
+ \item Complete(100\%) data - Number of students who scored more than 90\% across all regions
+ \item Each slice - Number of students who scored more than 90\% in each subject across all regions
+ \end{enumerate}
\end{frame}
\begin{frame}
@@ -161,9 +179,9 @@
\frametitle{File reading and parsing}
Understanding the structure of sslc1.txt
\begin{itemize}
- \item Each line in the file corresponds to one student's details
+ \item One line in file corresponds to a student's details
\item aka record
- \item Each record consists of several fields separated by a ';'
+ \item Each record consists of fields separated by ';'
\end{itemize}
\end{frame}
@@ -235,6 +253,19 @@ Out[6]: ["I'll be back", 42]
\end{frame}
\begin{frame}[fragile]
+ \frametitle{Back to lists: Iterating}
+ \begin{itemize}
+ \item Python's \kwrd{for} loop iterates through list items
+ \item In other languages (C/C++) we run through indices and pick items from the array using these indices
+ \item In Python, while iterating through list items current position is not available
+ \end{itemize}
+ \begin{block}{Iterating through indices}
+ What if we want the index of an item of a list?
+ \end{block}
+
+\end{frame}
+
+\begin{frame}[fragile]
\frametitle{enumerate: Iterating through list indices}
\begin{lstlisting}
In [1]: names = ["Guido","Alex", "Tim"]
@@ -250,7 +281,7 @@ In [2]: for i, name in enumerate(names):
\end{frame}
\begin{frame}[fragile]
- \frametitle{Dictionary: Building parsed data}
+ \frametitle{Continuing with our Dictionary}
Let our dictionary be:
\begin{lstlisting}
science = {} # is an empty dictionary
@@ -296,7 +327,7 @@ if score > 90:
\end{lstlisting}
\end{frame}
-\subsection{Visualizing the data}
+\subsection{Visualizing data}
\begin{frame}[fragile]
\frametitle{Pie charts}
\small
@@ -388,7 +419,59 @@ savefig('/tmp/all_regions.png')
\includegraphics[height=3in, interpolate=true]{data/all_regions}
\end{frame}
-\subsection{Obtaining stastics}
+\subsection{Obtaining statistics}
+\begin{frame}[fragile]
+ \frametitle{Obtaining statistics}
+ \begin{block}{Statistics: Mean}
+ Obtain the mean of Math scores
+ \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Obtaining statistics: Solution}
+ \begin{block}{Statistics: Mean}
+ Obtain the mean of Math scores
+ \end{block}
+ \begin{lstlisting}
+math_scores = scores[2]
+total = 0
+for i, score in enumerate(math_scores):
+ total += score
+
+mean = total / (i + 1)
+print "Mean: ", mean
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Obtaining statistics: Another solution}
+ \begin{block}{Statistics: Mean}
+ Obtain the mean of Math scores
+ \end{block}
+ \begin{lstlisting}
+math_scores = scores[2]
+mean = sum(math_scores) /
+ len(math_scores)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{NumPy arrays}
+ \begin{itemize}
+ \item NumPy provides arrays
+ \item arrays are very efficient and powerful
+ \item Very easy to perform element-wise operations - \typ{+, -, *, /, \%}
+ \begin{lstlisting}
+In [1]: a = array([1, 2, 3])
+In [2]: b = array([4, 5, 6])
+
+In [3]: a + b
+Out[3]: array([5, 7, 9])
+ \end{lstlisting}
+ \item Very easy to compute statistics
+ \end{itemize}
+\end{frame}
+
\begin{frame}[fragile]
\frametitle{Obtaining statistics}
\begin{lstlisting}
@@ -416,6 +499,7 @@ print "Standard Deviation: ",
\end{itemize}
\end{frame}
+\section{Least square fit}
\begin{frame}
\frametitle{L vs $T^2$ \ldots}
Let's go back to the L vs $T^2$ plot
@@ -444,17 +528,6 @@ In []: TSq = T*T
\end{frame}
\begin{frame}[fragile]
-\frametitle{Arrays}
-\begin{itemize}
-\item \typ{T} and \typ{L} are now arrays
-\item arrays are very efficient and powerful
-\item Very easy to perform element-wise operations
-\item \typ{+, -, *, /, \%}
-\item More about arrays later
-\end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
\frametitle{Least Squares Fit}
\vspace{-0.15in}
\begin{figure}
@@ -508,6 +581,7 @@ In []: TSq = T*T
\end{itemize}
\end{frame}
+\subsection{Van der Monde matrix generation}
\begin{frame}[fragile]
\frametitle{Van der Monde Matrix}
\begin{itemize}
@@ -540,6 +614,7 @@ In []: coef, res, r, s = lstsq(A,TSq)
\end{lstlisting}
\end{frame}
+\subsection{Plotting}
\begin{frame}[fragile]
\frametitle{Least Square Fit Line \ldots}
We get the points of the line from \typ{coef}
@@ -554,4 +629,13 @@ In []: plot(L, Tline)
\end{lstlisting}
\end{frame}
+\begin{frame}[fragile]
+ \frametitle{What did we learn?}
+ \begin{itemize}
+ \item Least square fit
+ \item Van der Monde matrix generation
+ \item Plotting the least square fit curve
+ \end{itemize}
+\end{frame}
+
\end{document}
diff --git a/day1/sslc1.py b/day1/sslc1.py
new file mode 100644
index 0000000..4745663
--- /dev/null
+++ b/day1/sslc1.py
@@ -0,0 +1,50 @@
+from pylab import *
+from scipy import *
+from scipy import stats
+
+scores = [[], [], [], [], []]
+ninety_percents = [{}, {}, {}, {}, {}]
+
+for record in open('sslc1.txt'):
+ record = record.strip()
+ fields = record.split(';')
+
+ region_code = fields[0].strip()
+
+ for i, field in enumerate(fields[3:8]):
+ if region_code not in ninety_percents[i]:
+ ninety_percents[i][region_code] = 0
+ score_str = field.strip()
+ score = 0 if score_str == 'AA' else int(score_str)
+ scores[i].append(score)
+ if score > 90:
+ ninety_percents[i][region_code] += 1
+
+subj_total = []
+for subject in ninety_percents:
+ subj_total.append(sum(subject.values()))
+
+
+figure(1)
+pie(ninety_percents[3].values(), labels=ninety_percents[3].keys())
+title('Students scoring 90% and above in science by region')
+savefig('/tmp/science.png')
+
+figure(2)
+pie(subj_total, labels=['English', 'Hindi', 'Maths', 'Science', 'Social'])
+title('Students scoring more than 90% by subject(All regions combined).')
+savefig('/tmp/all_regions.png')
+
+math_scores = array(scores[2])
+# Mean score in Maths(All regions combined)
+print "Mean: ", mean(math_scores)
+
+# Median score in Maths(All regions combined)
+print "Median: ", median(math_scores)
+
+# Mode score in Maths(All regions combined)
+print "Mode: ", stats.mode(math_scores)
+
+# Standard deviation of scores in Maths(All regions combined)
+print "Standard Deviation: ", std(math_scores)
+
diff --git a/day2/session1.tex b/day2/session1.tex
index 8e48816..6ebb280 100644
--- a/day2/session1.tex
+++ b/day2/session1.tex
@@ -73,7 +73,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
-\title[Basic Python]{Python:\\A formal approach}
+\title[Basic Python]{Python language: Basics}
\author[FOSSEE Team] {The FOSSEE Group}
@@ -138,7 +138,7 @@
\begin{frame}[fragile]
\frametitle{Numbers}
\begin{itemize}
- \item \kwrd{int}\\ Any whole number is an \kwrd{int}, no matter what the size!
+ \item \kwrd{int}\\ \kwrd{int} = whole number, no matter what the size!
\begin{lstlisting}
In [1]: a = 13
@@ -302,8 +302,8 @@ In [2]: p = 'World'
In [3]: s + p
Out[3]: 'Hello World'
-In [4]: s * 12
-Out[4]: 'Hello Hello Hello Hello ...'
+In [4]: s * 4
+Out[4]: 'Hello Hello Hello Hello'
\end{lstlisting}
\end{frame}
@@ -369,24 +369,36 @@ In [3]: a = "Now I am a string!"
\item Comments:
\begin{lstlisting}
In [4]: a = 1 # In-line comments
-In [5]: # Comment in a line to itself.
-In [6]: a = "# This is not a comment!"
+In [5]: # A comment line.
+In [6]: a = "# Not a comment!"
\end{lstlisting}
\end{itemize}
\inctime{15}
\end{frame}
\section{Simple IO}
-\begin{frame}{Simple IO}
- \begin{block}
- {Console Input}
- \texttt{raw\_input()} waits for user input.\\Prompt string is optional.\\
- All keystrokes are Strings!\\\texttt{int()} converts string to int.
- \end{block}
- \begin{block}
- {Console output}
- \texttt{print} is straight forward. Note the distinction between \texttt{print x} and \texttt{print x,}
- \end{block}
+\begin{frame}[fragile]
+ \frametitle{Simple IO: Console Input}
+ \begin{itemize}
+ \item raw\_input() waits for user input.
+ \begin{lstlisting}
+In [1]: a = raw_input()
+5
+
+In [2]: a = raw_input('prompt > ')
+prompt > 5
+ \end{lstlisting}
+ \item Prompt string is optional.
+ \item All keystrokes are Strings!
+ \item \texttt{int()} converts string to int.
+ \end{itemize}
+\end{frame}
+
+\begin{frame}{Simple IO: Console output}
+ \begin{itemize}
+ \item \texttt{print} is straight forward
+ \item Note the distinction between \texttt{print x} and \texttt{print x,}
+ \end{itemize}
\end{frame}
\section{Control flow}
@@ -437,8 +449,9 @@ while b < 10:
\frametitle{\typ{range()}}
\kwrd{range([start,] stop[, step])}\\
\begin{itemize}
- \item \alert {range() returns a list of integers}
- \item \alert {The start and the step arguments are optional}
+ \item range() returns a list of integers
+ \item The \emph{start} and the \emph{step} arguments are optional
+ \item \emph{stop} argument is not included in the list
\end{itemize}
\end{frame}
@@ -448,8 +461,8 @@ Example: print squares of first \typ{n} numbers
\begin{lstlisting}
In []: for i in range(5):
....: print i, i * i
- ....:
- ....:
+ ....:
+ ....:
0 0
1 1
2 4
@@ -460,20 +473,13 @@ In []: for i in range(5):
\end{frame}
\subsection{Exercises}
-\begin{frame}
- \frametitle{Problem set 1}
- \begin{itemize}
- \item All the problems can be\\
- solved using \kwrd{if} and \kwrd{while}
- \end{itemize}
-\end{frame}
-\begin{frame}{Problem 1.1}
+\begin{frame}{Problem set 1: Problem 1.1}
Write a program that displays all three digit numbers that are equal to the sum of the cubes of their digits. That is, print numbers $abc$ that have the property $abc = a^3 + b^3 + c^3$\\
\vspace*{0.2in}
\emphbar{These are called $Armstrong$ numbers.}
\end{frame}
-
+
\begin{frame}{Problem 1.2 - Collatz sequence}
\begin{enumerate}
\item Start with an arbitrary (positive) integer.
@@ -495,14 +501,14 @@ In []: for i in range(5):
The number of lines must be obtained from the user as input.\\
\pause
\emphbar{When can your code fail?}
-\only<2->{\inctime{10}}
+\inctime{5}
\end{frame}
\begin{frame}[fragile]
\frametitle{What did we learn?}
\begin{itemize}
\item Basic data types
- \item Arithematic, logical and relational operations
+ \item Operators
\item Conditional structures
\item Loops
\end{itemize}
diff --git a/day2/session2.tex b/day2/session2.tex
index dd2b8c5..7aadfc1 100644
--- a/day2/session2.tex
+++ b/day2/session2.tex
@@ -73,7 +73,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
-\title[Basic Python]{Python:\\A formal approach}
+\title[Basic Python]{Python language: Data structures and functions}
\author[FOSSEE Team] {The FOSSEE Group}
@@ -215,7 +215,7 @@ Out[]: 52.530000000000001
\end{frame}
\begin{frame} {Problem Set 2.1: Problem 2.1.1}
-You are given date strings of the form ``29, Jul 2009'', or ``4 January 2008''. In other words a number a string and another number, with a comma sometimes separating the items.Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints.
+You are given date strings of the form ``29, Jul 2009'', or ``4 January 2008''. In other words a number, a string and another number, with a comma sometimes separating the items.\\Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints.
\end{frame}
\subsection{Set}
@@ -261,7 +261,7 @@ False
\frametitle{Problem set 2.2}
\begin{description}
\item[2.2.1] Given a dictionary of the names of students and their marks, identify how many duplicate marks are there? and what are these?
- \item[2.2.2] Given a string of the form ``4-7, 9, 12, 15'' find the numbers missing in this list for a given range.
+ \item[2.2.2] Given a string of the form ``4-7, 9, 12, 15'' find the missing numbers in the given range.
\end{description}
\inctime{15}
\end{frame}