|
1 % Created 2010-11-03 Wed 15:37 |
|
2 \documentclass[presentation]{beamer} |
|
3 \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent} |
|
4 \usepackage[latin1]{inputenc} |
|
5 \usepackage[T1]{fontenc} |
|
6 \usepackage{graphicx} |
|
7 \usepackage{longtable} |
|
8 \usepackage{float} |
|
9 \usepackage{wrapfig} |
|
10 \usepackage{soul} |
|
11 \usepackage{amssymb} |
|
12 \usepackage{hyperref} |
|
13 \usepackage[english]{babel} \usepackage{ae,aecompl} |
|
14 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
|
15 \usepackage{listings} |
|
16 \lstset{language=Python, basicstyle=\ttfamily\bfseries, |
|
17 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
|
18 showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
|
19 |
|
20 \title{Accessing parts of arrays} |
|
21 \author{FOSSEE} |
|
22 \date{} |
|
23 |
|
24 \begin{document} |
|
25 |
|
26 \maketitle |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 \begin{frame} |
|
37 \frametitle{Outline} |
|
38 \label{sec-1} |
|
39 |
|
40 \begin{itemize} |
|
41 \item Manipulating one and multi dimensional arrays |
|
42 \item Access and change individual elements |
|
43 \item Access and change rows and columns |
|
44 \item Slicing and striding on arrays to access chunks |
|
45 \item Read images into arrays and manipulations |
|
46 \end{itemize} |
|
47 \end{frame} |
|
48 \begin{frame}[fragile] |
|
49 \frametitle{Sample Arrays} |
|
50 \label{sec-2} |
|
51 |
|
52 \begin{verbatim} |
|
53 In []: A = array([12, 23, 34, 45, 56]) |
|
54 |
|
55 In []: C = array([[11, 12, 13, 14, 15], |
|
56 [21, 22, 23, 24, 25], |
|
57 [31, 32, 33, 34, 35], |
|
58 [41, 42, 43, 44, 45], |
|
59 [51, 52, 53, 54, 55]]) |
|
60 \end{verbatim} |
|
61 \end{frame} |
|
62 \begin{frame} |
|
63 \frametitle{Question 1} |
|
64 \label{sec-3} |
|
65 |
|
66 Change the last column of \texttt{C} to zeroes. |
|
67 \end{frame} |
|
68 \begin{frame}[fragile] |
|
69 \frametitle{Solution 1} |
|
70 \label{sec-4} |
|
71 |
|
72 \begin{verbatim} |
|
73 In []: C[:, -1] = 0 |
|
74 \end{verbatim} |
|
75 \end{frame} |
|
76 \begin{frame} |
|
77 \frametitle{Question 2} |
|
78 \label{sec-5} |
|
79 |
|
80 Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}. |
|
81 \end{frame} |
|
82 \begin{frame}[fragile] |
|
83 \frametitle{Solution 2} |
|
84 \label{sec-6} |
|
85 |
|
86 \begin{verbatim} |
|
87 In []: A[:] = [11, 12, 13, 14, 15] |
|
88 \end{verbatim} |
|
89 \end{frame} |
|
90 \begin{frame} |
|
91 \frametitle{squares.png} |
|
92 \label{sec-7} |
|
93 |
|
94 \begin{center} |
|
95 \includegraphics[scale=0.6]{squares} |
|
96 \end{center} |
|
97 \end{frame} |
|
98 \begin{frame} |
|
99 \frametitle{Question 3} |
|
100 \label{sec-8} |
|
101 |
|
102 \begin{itemize} |
|
103 \item obtain \texttt{[22, 23]} from \texttt{C}. |
|
104 \item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}. |
|
105 \item obtain \texttt{[21, 31, 41, 0]}. |
|
106 \end{itemize} |
|
107 \end{frame} |
|
108 \begin{frame}[fragile] |
|
109 \frametitle{Solution 3} |
|
110 \label{sec-9} |
|
111 |
|
112 \begin{verbatim} |
|
113 In []: C[1, 1:3] |
|
114 In []: C[0:4, 0] |
|
115 In []: C[1:5, 0] |
|
116 \end{verbatim} |
|
117 \end{frame} |
|
118 \begin{frame} |
|
119 \frametitle{Question 4} |
|
120 \label{sec-10} |
|
121 |
|
122 Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C} |
|
123 \end{frame} |
|
124 \begin{frame}[fragile] |
|
125 \frametitle{Solution 4} |
|
126 \label{sec-11} |
|
127 |
|
128 \begin{verbatim} |
|
129 In []: C[1:3, 2:4] |
|
130 \end{verbatim} |
|
131 \end{frame} |
|
132 \begin{frame} |
|
133 \frametitle{Question 5} |
|
134 \label{sec-12} |
|
135 |
|
136 Obtain the square in the center of the image |
|
137 \end{frame} |
|
138 \begin{frame}[fragile] |
|
139 \frametitle{Solution 5} |
|
140 \label{sec-13} |
|
141 |
|
142 \begin{verbatim} |
|
143 In []: imshow(I[75:225, 75:225]) |
|
144 \end{verbatim} |
|
145 \end{frame} |
|
146 \begin{frame}[fragile] |
|
147 \frametitle{Question 6} |
|
148 \label{sec-14} |
|
149 |
|
150 Obtain the following |
|
151 \begin{verbatim} |
|
152 [[12, 0], [42, 0]] |
|
153 [[12, 13, 14], [0, 0, 0]] |
|
154 \end{verbatim} |
|
155 \end{frame} |
|
156 \begin{frame}[fragile] |
|
157 \frametitle{Solution 6} |
|
158 \label{sec-15} |
|
159 |
|
160 \begin{verbatim} |
|
161 In []: C[::3, 1::3] |
|
162 In []: C[::4, 1:4] |
|
163 \end{verbatim} |
|
164 \end{frame} |
|
165 \begin{frame} |
|
166 \frametitle{Summary} |
|
167 \label{sec-16} |
|
168 |
|
169 You should now be able to -- |
|
170 \begin{itemize} |
|
171 \item Manipulate single \& multi dimensional arrays |
|
172 |
|
173 \begin{itemize} |
|
174 \item Access and change individual elements |
|
175 \item Access and change rows and columns |
|
176 \item Slice and stride on arrays |
|
177 \end{itemize} |
|
178 |
|
179 \item Read images into arrays and manipulate them. |
|
180 \end{itemize} |
|
181 \end{frame} |
|
182 \begin{frame} |
|
183 \frametitle{Thank you!} |
|
184 \label{sec-17} |
|
185 |
|
186 \begin{block}{} |
|
187 \begin{center} |
|
188 This spoken tutorial has been produced by the |
|
189 \textcolor{blue}{FOSSEE} team, which is funded by the |
|
190 \end{center} |
|
191 \begin{center} |
|
192 \textcolor{blue}{National Mission on Education through \\ |
|
193 Information \& Communication Technology \\ |
|
194 MHRD, Govt. of India}. |
|
195 \end{center} |
|
196 \end{block} |
|
197 \end{frame} |
|
198 |
|
199 \end{document} |