day1quiz2.tex
changeset 261 9cce24d00957
child 306 57291186d598
equal deleted inserted replaced
259:bb77a470e00a 261:9cce24d00957
       
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
     2 % Tutorial slides on Python.
       
     3 %
       
     4 % Author: FOSSEE <info at fossee  dot in>
       
     5 % Copyright (c) 2005-2009, FOSSEE Team
       
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
     7 
       
     8 
       
     9 \documentclass[14pt,compress]{beamer}
       
    10 
       
    11 \mode<presentation>
       
    12 {
       
    13   \useoutertheme{split}
       
    14   \setbeamercovered{transparent}
       
    15 }
       
    16 
       
    17 \definecolor{darkgreen}{rgb}{0,0.5,0}
       
    18 
       
    19 \usepackage{listings}
       
    20 \lstset{language=Python,
       
    21     basicstyle=\ttfamily\bfseries,
       
    22     commentstyle=\color{red}\itshape,
       
    23   stringstyle=\color{darkgreen},
       
    24   showstringspaces=false,
       
    25   keywordstyle=\color{blue}\bfseries}
       
    26 
       
    27 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
       
    28 
       
    29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    30 % Macros
       
    31 
       
    32 \newcounter{qno}
       
    33 \setcounter{qno}{0}
       
    34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}}
       
    35 
       
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    37 % Title page
       
    38 \title[Basic Python]{Python: Quiz}
       
    39 
       
    40 \author[FOSSEE Team] {FOSSEE}
       
    41 
       
    42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
       
    43 \date[] {11, October 2009\\Day 2}
       
    44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    45 
       
    46 
       
    47 \begin{document}
       
    48 
       
    49 \begin{frame}
       
    50   \titlepage
       
    51 \end{frame}
       
    52 
       
    53 \begin{frame}
       
    54   \frametitle{Write your details...}
       
    55 On the top right hand corner please write down the following:
       
    56   \begin{itemize}
       
    57     \item  Name:
       
    58     \item Affliation:
       
    59     \item Occupation:
       
    60   \end{itemize}
       
    61 \end{frame}
       
    62 
       
    63 \begin{frame}[fragile]
       
    64 \frametitle{\incqno }
       
    65 \begin{lstlisting}
       
    66   >>> x = array([[1,2,3,4],[3,4,2,5]])
       
    67   >>> x.shape
       
    68   (2, 4)
       
    69 \end{lstlisting}
       
    70 Change the shape of \lstinline+x+ to (4,2)
       
    71 \end{frame}
       
    72 
       
    73 \begin{frame}[fragile]
       
    74 \frametitle{\incqno }
       
    75 \begin{lstlisting}
       
    76   >>> x = array([[1,2,3,4]])
       
    77 \end{lstlisting}
       
    78 How to change the third element of \lstinline+x+ to 0?
       
    79 \end{frame}
       
    80 
       
    81 \begin{frame}[fragile]
       
    82 \frametitle{\incqno }
       
    83 What would be the result?
       
    84 \begin{lstlisting}
       
    85   >>> y = arange(3)
       
    86   >>> x = linspace(0,3,3)
       
    87   >>> x-y
       
    88 \end{lstlisting}
       
    89 \end{frame}
       
    90 
       
    91 \begin{frame}[fragile]
       
    92 \frametitle{\incqno }
       
    93 \begin{lstlisting}
       
    94   >>> x = array([0, 1, 2, 3])
       
    95   >>> x.shape = 2,2
       
    96   >>> x
       
    97   array([[0, 1],
       
    98          [2, 3]])
       
    99   >>> x[::2,::2]
       
   100 \end{lstlisting}
       
   101 What is the output?
       
   102 \end{frame}
       
   103 
       
   104 \begin{frame}[fragile]
       
   105 \frametitle{\incqno }
       
   106 What would be the result?
       
   107 \begin{lstlisting}
       
   108   >>> x
       
   109   array([[0, 1, 2],
       
   110          [3, 4, 5],
       
   111          [6, 7, 8]])
       
   112   >>> x[::-1,:]
       
   113 \end{lstlisting}
       
   114 Hint:
       
   115 \begin{lstlisting}
       
   116   >>> x = arange(9)
       
   117   >>> x[::-1]
       
   118   array([8, 7, 6, 5, 4, 3, 2, 1, 0])
       
   119 \end{lstlisting}
       
   120 \end{frame}
       
   121 
       
   122 \begin{frame}[fragile]
       
   123 \frametitle{\incqno }
       
   124 \begin{lstlisting}
       
   125   >>> x
       
   126   array([[ 0, 1, 2, 3],
       
   127          [ 4, 5, 6, 7],
       
   128          [ 8, 9, 10, 11],
       
   129          [12, 13, 14, 15]])
       
   130 \end{lstlisting}
       
   131 How will you get the following \lstinline+x+?
       
   132 \begin{lstlisting}
       
   133   array([[ 5, 7],
       
   134          [ 9, 11]])
       
   135 \end{lstlisting}
       
   136 \end{frame}
       
   137 
       
   138 \begin{frame}[fragile]
       
   139 \frametitle{\incqno }
       
   140 \begin{lstlisting}
       
   141   >>> x = array(([1,2,3,4],[2,3,4,5]))
       
   142   >>> x[-2][-3] = 4
       
   143   >>> x
       
   144 \end{lstlisting}
       
   145 What will be printed?
       
   146 \end{frame}
       
   147 
       
   148 \begin{frame}[fragile]
       
   149 \frametitle{\incqno }
       
   150 What would be the output?
       
   151 \begin{lstlisting}
       
   152   >>> y = arange(4)
       
   153   >>> x = array(([1,2,3,2],[1,3,6,0]))
       
   154   >>> x + y
       
   155 \end{lstlisting}
       
   156 \end{frame}
       
   157 
       
   158 \begin{frame}[fragile]
       
   159 \frametitle{\incqno }
       
   160 \begin{lstlisting}
       
   161   >>> line = plot(x, sin(x))
       
   162 \end{lstlisting}
       
   163 Use the \lstinline+set_linewidth+ method to set width of \lstinline+line+ to 2.
       
   164 \end{frame}
       
   165 
       
   166 \begin{frame}[fragile]
       
   167 \frametitle{\incqno }
       
   168 What would be the output?
       
   169 \begin{lstlisting}
       
   170   >>> x = arange(9)
       
   171   >>> y = arange(9.)
       
   172   >>> x == y
       
   173 \end{lstlisting}
       
   174 \end{frame}
       
   175 
       
   176 
       
   177 \end{document}
       
   178