equal
deleted
inserted
replaced
35 arrays, get rows and columns and other chunks of arrays using |
35 arrays, get rows and columns and other chunks of arrays using |
36 slicing and striding. |
36 slicing and striding. |
37 |
37 |
38 {{{ switch back to the terminal }}} |
38 {{{ switch back to the terminal }}} |
39 |
39 |
40 .. #[[Anoop: context switch, switch to next slide should be added]] |
|
41 |
|
42 As usual, we start IPython, using |
40 As usual, we start IPython, using |
43 :: |
41 :: |
44 |
42 |
45 ipython -pylab |
43 ipython -pylab |
|
44 |
|
45 |
|
46 {{ Show the slide with the arrays, A and C }} |
46 |
47 |
47 Let us have two arrays, A and C, as the sample arrays that we will |
48 Let us have two arrays, A and C, as the sample arrays that we will |
48 use to work through this tutorial. |
49 use to work through this tutorial. |
49 |
50 |
50 :: |
51 :: |
67 To access, the element 34 in A, we say, |
68 To access, the element 34 in A, we say, |
68 |
69 |
69 :: |
70 :: |
70 |
71 |
71 A[2] |
72 A[2] |
72 |
|
73 .. #[[Anoop: should be A[2], corrected it]] |
|
74 |
73 |
75 Like lists, indexing starts from 0 in arrays, too. So, 34, the |
74 Like lists, indexing starts from 0 in arrays, too. So, 34, the |
76 third element has the index 2. |
75 third element has the index 2. |
77 |
76 |
78 Now, let us access the element 34 from C. To do this, we say |
77 Now, let us access the element 34 from C. To do this, we say |
132 |
131 |
133 C[:, 2] |
132 C[:, 2] |
134 |
133 |
135 Following is an exercise that you must do. |
134 Following is an exercise that you must do. |
136 |
135 |
137 .. #[[Anoop: add context switches, switch to next slide]] |
136 {{ show slide containing Question 1}} |
138 |
137 |
139 %%1%% Change the last column of C to zeroes. |
138 %%1%% Change the last column of C to zeroes. |
140 |
139 |
141 Please, pause the video here. Do the exercises and then continue. |
140 Please, pause the video here. Do the exercises and then continue. |
142 |
141 |
152 |
151 |
153 gives the whole of A. |
152 gives the whole of A. |
154 |
153 |
155 Following is an exercise that you must do. |
154 Following is an exercise that you must do. |
156 |
155 |
157 .. #[[Anoop: add context switches, switch to next slide]] |
156 {{ show slide containing Question 2}} |
158 |
157 |
159 %%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``. |
158 %%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``. |
160 |
159 |
161 Please, pause the video here. Do the exercises and then continue. |
160 Please, pause the video here. Do the exercises and then continue. |
162 |
161 |
198 |
197 |
199 I |
198 I |
200 |
199 |
201 at the prompt, and see that an array is displayed. |
200 at the prompt, and see that an array is displayed. |
202 |
201 |
203 To check the dimensions of any array, we can use the method |
202 To check the dimensions of any array, we can use ``.shape``. We say |
204 shape. We say |
|
205 |
|
206 .. #[[Anoop: method is a function and .shape is a tuple, so it can be named |
|
207 as value or something instead of the term method.]] |
|
208 |
203 |
209 :: |
204 :: |
210 |
205 |
211 I.shape |
206 I.shape |
212 |
207 |
240 |
235 |
241 C[2, 0:3] |
236 C[2, 0:3] |
242 |
237 |
243 Following is an exercise that you must do. |
238 Following is an exercise that you must do. |
244 |
239 |
245 .. #[[Anoop: add context switches, switch to next slide]] |
240 {{ show slide containing Question 3 }} |
246 |
241 |
247 %%3%% First, obtain the elements [22, 23] from C. Then, obtain the |
242 %%3%% First, obtain the elements [22, 23] from C. Then, obtain the |
248 elements [11, 21, 31, 41] from C. Finally, obtain the elements [21, |
243 elements [11, 21, 31, 41] from C. Finally, obtain the elements [21, |
249 31, 41, 0]. |
244 31, 41, 0]. |
250 |
245 |
251 Please, pause the video here. Do the exercises and then continue. |
246 Please, pause the video here. Do the exercises and then continue. |
252 |
247 |
253 .. #[[Anoop: add context switches, switch to next slide]] |
248 {{ show slide containing Solution 3 }} |
254 |
249 |
255 :: |
250 :: |
256 |
251 |
257 C[1, 1:3] |
252 C[1, 1:3] |
258 |
253 |
284 gives the elements [21, 31, 41, 0]. If we skip both the indexes, |
279 gives the elements [21, 31, 41, 0]. If we skip both the indexes, |
285 we get the slice from end to end, as we already know. |
280 we get the slice from end to end, as we already know. |
286 |
281 |
287 Following is an exercise that you must do. |
282 Following is an exercise that you must do. |
288 |
283 |
289 .. #[[Anoop: add context switches, switch to next slide]] |
284 {{ show slide containing Question 4 }} |
290 |
285 |
291 %%4%% Obtain the elements [[23, 24], [33, -34]] from C. |
286 %%4%% Obtain the elements [[23, 24], [33, -34]] from C. |
292 |
287 |
293 Please, pause the video here. Do the exercises and then continue. |
288 Please, pause the video here. Do the exercises and then continue. |
294 |
289 |
295 .. #[[Anoop: add context switches, switch to next slide]] |
290 {{ show slide containing Solution 4 }} |
296 |
291 |
297 :: |
292 :: |
298 |
293 |
299 C[1:3, 2:4] |
294 C[1:3, 2:4] |
300 |
295 |
316 |
311 |
317 imshow(I[:150, :150]) |
312 imshow(I[:150, :150]) |
318 |
313 |
319 Following is an exercise that you must do. |
314 Following is an exercise that you must do. |
320 |
315 |
321 .. #[[Anoop: add context switches, switch to next slide]] |
316 {{ show slide containing Question 5 }} |
322 |
317 |
323 %%5%% Obtain the square in the center of the image. |
318 %%5%% Obtain the square in the center of the image. |
324 |
319 |
325 Following is an exercise that you must do. |
320 Following is an exercise that you must do. |
326 |
321 |
327 .. #[[Anoop: add context switches, switch to next slide]] |
322 {{ show slide containing Solution 5 }} |
328 |
323 |
329 :: |
324 :: |
330 |
325 |
331 imshow(I[75:225, 75:225]) |
326 imshow(I[75:225, 75:225]) |
332 |
327 |
357 |
352 |
358 C[1::2, ::2] |
353 C[1::2, ::2] |
359 |
354 |
360 gives the elements, [[21, 23, 0], [41, 43, 0]] |
355 gives the elements, [[21, 23, 0], [41, 43, 0]] |
361 |
356 |
362 .. #[[Anoop: I think you forgot to "add switch to next slide" context |
357 {{ show slide containing Question 6 }} |
363 switch, I think it will be better you review the scripts(all) for |
|
364 context switches and add them.]] |
|
365 |
358 |
366 Following is an exercise that you must do. |
359 Following is an exercise that you must do. |
367 |
360 |
368 %%6%% Obtain the following. |
361 %%6%% Obtain the following. |
369 [[12, 0], [42, 0]] |
362 [[12, 0], [42, 0]] |
370 [[12, 13, 14], [0, 0, 0]] |
363 [[12, 13, 14], [0, 0, 0]] |
371 |
364 |
372 Please, pause the video here. Do the exercises and then continue. |
365 Please, pause the video here. Do the exercises and then continue. |
|
366 |
|
367 {{ show slide containing Solution 6 }} |
373 |
368 |
374 :: |
369 :: |
375 |
370 |
376 C[::3, 1::3] |
371 C[::3, 1::3] |
377 |
372 |
408 have learnt to access parts of arrays, specifically individual |
403 have learnt to access parts of arrays, specifically individual |
409 elements, rows and columns and larger pieces of arrays. We have |
404 elements, rows and columns and larger pieces of arrays. We have |
410 also learnt how to modify arrays, element wise or in larger |
405 also learnt how to modify arrays, element wise or in larger |
411 pieces. |
406 pieces. |
412 |
407 |
413 .. #[[Anoop: I think in the summary slide it is better to use single & |
408 {{{ Show the "sponsored by FOSSEE" slide }}} |
414 multi dimensional arrays instead of 1D and Multi dimensional arrays.]] |
409 |
415 |
410 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
416 .. #[[Anoop: switch to thank you slide, added comment as it most probably |
411 |
417 won't be noticed]] |
412 Hope you have enjoyed and found it useful. |
418 |
413 Thank you! |
419 Thank You! |
|
420 |
414 |
421 .. |
415 .. |
422 Local Variables: |
416 Local Variables: |
423 mode: rst |
417 mode: rst |
424 indent-tabs-mode: nil |
418 indent-tabs-mode: nil |