# HG changeset patch # User Nishanth # Date 1286426299 -19800 # Node ID 91852d9745d701bd26c416c74cfc6a5c5f283161 # Parent 8edaf377c801f2698d8b06ee1aad8941ef994041# Parent 5c647a197103386710470f643f326583de01c6be Merged with punch changes diff -r 5c647a197103 -r 91852d9745d7 accessing-pieces-arrays/questions.rst --- a/accessing-pieces-arrays/questions.rst Thu Oct 07 10:07:22 2010 +0530 +++ b/accessing-pieces-arrays/questions.rst Thu Oct 07 10:08:19 2010 +0530 @@ -1,17 +1,159 @@ -Objective ---------- +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. Given the array, ``A = array([12, 15, 18, 21])``, how do we access + the element ``18``? + + Answer: ``A[2]`` + +#. Given the array, ``A = array([12, 15, 18, 21])``, what element is + accessed by ``A[1]`` + + Answer: ``15`` + +#. Given the array, ``A = array([12, 15, 18, 21])``, what element is + accessed by ``A[-3]``? + + Answer: ``15`` + +#. Given the array, ``A = array([12, 15, 18, 21])``, how do you change + the element ``15`` to ``51``? + + Answer: ``A[1] = 51`` -.. A mininum of 8 questions here. +#. Given the array, ``A = array([12, 15, 18, 21])``, what is ``A`` + after the execution of the statement ``A[3] = 24``? + + Answer: ``array([12, 15, 18, 24])`` + +#. Given the array, ``A = array([12, 15, 18, 21])``, what is the + result of the statement, ``A[4] = 24``? + + Answer: IndexError: index out of bounds + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do we + access the element ``18``? + + Answer: ``A[0, 0]`` + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the + result of ``B[1]``? + + Answer: ``array([18, 21])`` + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the + result of ``B[1, 1]``? + + Answer: ``21`` + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, what element + is accessed by ``B[-1, -2]``? -1. Question 1 -2. Question 2 -3. Question 3 + Answer: ``18`` + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do you + change the element ``15`` to ``51``? + + Answer: ``B[0, 1] = 51`` + +#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the + value of B, after executing, ``B[0] = 0``? + + Answer: ``array([[0, 0], [18, 21]])`` + +#. Given the array, + + :: + + B = array([[10, 11, 12, 13], + [20, 21, 22, 23], + [30, 31, 32, 33], + [40, 41, 42, 43]]) + + Obtain the elements, ``[[21, 22], [32, 32]]`` + + Answer: ``B[1:3, 1:3]`` +#. Given the array, + + :: + + B = array([[10, 11, 12, 13], + [20, 21, 22, 23], + [30, 31, 32, 33], + [40, 41, 42, 43]]) + Obtain the elements, ``[[10, 13], [30, 33]]`` + + Answer: ``B[::2, ::3]`` + +#. What command is used to read an image file? + + a. imshow + #. imread + #. imopen + #. open + + Answer: ``imread`` + +#. If ``P`` is ``array([12, 13, 14, 15])`` then ``P.shape`` gives + ``(4, 1)``. True or False? + + Answer: False + Larger Questions ---------------- -.. A minimum of 2 questions here. +.. A minimum of 2 questions here (along with answers) + +1. Given the array, + :: + + B = array([[10, 11, 12, 13], + [20, 21, 22, 23], + [30, 31, 32, 33], + [40, 41, 42, 43]]) + + Change the array to + :: + + B = array([[10, 11, 10, 11], + [20, 21, 20, 21], + [10, 11, 10, 11], + [20, 21, 20, 21]]) + + using slicing and striding. + + Answer:: + + B[:2, 2:] = B[:2, :2] + B[2:, :2] = B[:2, :2] + B[2:, 2:] = B[:2, :2] -1. Programming Assignment 1 -2. Programming Assignment 2 +#. Find out how to display a grayscale image with proper colors. Hint, + use ``?`` on ``imshow``. + + Answer: ``cmap=cm.gray`` + +#. From the image, ``tagore-einstein.png``, + a. show only the face of Einstein. + b. show only the face of Tagore. + + Hint, use ``imread`` to read the image and ``imshow`` to show the + image. Use ``cm.gray`` as ``cmap`` to display the image properly. + + Answer:: + + F = imread('tagore-einstein.png') + imshow(F[:210, 20:180], cmap=cm.gray) + + F = imread('tagore-einstein.png') + imshow(F[30:300, 320:480], cmap=cm.gray) + +.. #[Puneeth: This question contains answer to previous +.. question. Shouldn't be shown at the same time.] + + + diff -r 5c647a197103 -r 91852d9745d7 accessing-pieces-arrays/script.rst --- a/accessing-pieces-arrays/script.rst Thu Oct 07 10:07:22 2010 +0530 +++ b/accessing-pieces-arrays/script.rst Thu Oct 07 10:08:19 2010 +0530 @@ -1,7 +1,15 @@ .. Objectives .. ---------- - -.. Clearly state the objectives of the LO (along with RBT level) + + By the end of this tutorial, you will be able to: + + 1. Access and change individual elements of arrays, both one + dimensional and multi-dimensional. + 2. Access and change rows and columns of arrays. + 3. Access and change other chunks from an array, using slicing + and striding. + 4. Read images into arrays and perform processing on them, using + simple array manipulations. .. Prerequisites .. ------------- @@ -18,7 +26,6 @@ Script ------ - {{{ Screen shows welcome slide }}} Welcome to the tutorial on accessing pieces of arrays diff -r 5c647a197103 -r 91852d9745d7 accessing-pieces-arrays/tagore-einstein.png Binary file accessing-pieces-arrays/tagore-einstein.png has changed diff -r 5c647a197103 -r 91852d9745d7 template/questions.rst --- a/template/questions.rst Thu Oct 07 10:07:22 2010 +0530 +++ b/template/questions.rst Thu Oct 07 10:08:19 2010 +0530 @@ -1,17 +1,28 @@ -Objective ---------- +Objective Questions +------------------- -.. A mininum of 8 questions here. +.. A mininum of 8 questions here (along with answers) 1. Question 1 + + Answer: Answer 1 + + OR + + Answer:: + + answer code line 1 + answer code line 2 + answer code line 3 + 2. Question 2 3. Question 3 -Larger Problems ---------------- +Larger Questions +---------------- -.. A minimum of 2 questions here. +.. A minimum of 2 questions here (along with answers) 1. Question 1 2. Question 2 diff -r 5c647a197103 -r 91852d9745d7 template/script.rst --- a/template/script.rst Thu Oct 07 10:07:22 2010 +0530 +++ b/template/script.rst Thu Oct 07 10:08:19 2010 +0530 @@ -22,7 +22,7 @@ Hello Friends. Welcome to the tutorial on so-and-so (topic of the tutorial) -{{{ Show the slide containing the outline slide }}} +{{{ Show the outline slide }}} ... @@ -34,7 +34,7 @@ %% %% yet another exercise -Please, pause the video here. Do the exercises and then continue. +Please, pause the video here. Do the exercise(s) and then continue. {{{ Show summary slide }}}