accessing-pieces-arrays/questions.rst
author anand
Thu, 11 Nov 2010 00:03:57 +0530
changeset 472 fcdec2d28c9a
parent 224 4e0cdb5cca53
permissions -rw-r--r--
Checklist OK for `The other kinds of plots`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     1
Objective Questions
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     2
-------------------
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     3
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     4
.. A mininum of 8 questions here (along with answers)
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     5
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
1. Given the array, ``A = array([12, 15, 18, 21])``, how do we access
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
   the element ``18``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     9
   Answer: ``A[2]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    11
#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    12
   accessed by ``A[1]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    13
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    14
   Answer: ``15``  
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    15
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    16
#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    17
   accessed by ``A[-3]``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    18
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    19
   Answer: ``15``  
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    20
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    21
#. Given the array, ``A = array([12, 15, 18, 21])``, how do you change
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    22
   the element ``15`` to ``51``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    23
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    24
   Answer: ``A[1] = 51``
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    26
#. Given the array, ``A = array([12, 15, 18, 21])``, what is ``A``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    27
   after the execution of the statement ``A[3] = 24``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    28
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    29
   Answer: ``array([12, 15, 18, 24])``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    30
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    31
#. Given the array, ``A = array([12, 15, 18, 21])``, what is the
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    32
   result of the statement, ``A[4] = 24``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    33
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    34
   Answer: IndexError: index out of bounds
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    35
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    36
#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do we
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    37
   access the element ``18``? 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    38
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    39
   Answer: ``A[0, 0]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    40
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    41
#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    42
   result of ``B[1]``? 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    43
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    44
   Answer:  ``array([18, 21])``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    45
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    46
#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    47
   result of ``B[1, 1]``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    48
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    49
   Answer:  ``21``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    50
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    51
#. Given the array, ``B = array([[12, 15], [18, 21]])``, what element
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    52
   is accessed by ``B[-1, -2]``?
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    54
   Answer:  ``18``   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    55
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    56
#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do you
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    57
   change the element ``15`` to ``51``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    58
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    59
   Answer:  ``B[0, 1] = 51``   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    60
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    61
#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    62
   value of B, after executing, ``B[0] = 0``?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    63
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    64
   Answer:  ``array([[0, 0], [18, 21]])``   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    65
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    66
#. Given the array, 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    67
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    68
   ::
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    69
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    70
     B = array([[10, 11, 12, 13],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    71
                [20, 21, 22, 23],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    72
                [30, 31, 32, 33],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    73
                [40, 41, 42, 43]])
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    74
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    75
   Obtain the elements, ``[[21, 22], [32, 32]]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    76
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    77
   Answer:  ``B[1:3, 1:3]``   
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    78
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    79
#. Given the array, 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    80
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    81
   ::
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    82
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    83
     B = array([[10, 11, 12, 13],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    84
                [20, 21, 22, 23],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    85
                [30, 31, 32, 33],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    86
                [40, 41, 42, 43]])
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    87
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    88
   Obtain the elements, ``[[10, 13], [30, 33]]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    89
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    90
   Answer:  ``B[::2, ::3]``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    91
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    92
#. What command is used to read an image file?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    93
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    94
   a. imshow
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    95
   #. imread
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    96
   #. imopen
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    97
   #. open
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    98
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    99
   Answer: ``imread``   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   100
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   101
#. If ``P`` is ``array([12, 13, 14, 15])`` then ``P.shape`` gives
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   102
   ``(4, 1)``. True or False?
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   103
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   104
   Answer: False
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   105
     
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   106
Larger Questions
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   107
----------------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   108
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   109
.. A minimum of 2 questions here (along with answers)
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   110
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   111
1. Given the array, 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   112
   ::
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   113
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   114
     B = array([[10, 11, 12, 13],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   115
                [20, 21, 22, 23],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   116
                [30, 31, 32, 33],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   117
                [40, 41, 42, 43]])
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   118
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   119
   Change the array to 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   120
   ::
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   121
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   122
     B = array([[10, 11, 10, 11],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   123
                [20, 21, 20, 21],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   124
                [10, 11, 10, 11],
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   125
                [20, 21, 20, 21]])
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   126
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   127
   using slicing and striding. 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   128
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   129
   Answer::
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   130
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   131
     B[:2, 2:] = B[:2, :2]
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   132
     B[2:, :2] = B[:2, :2]
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   133
     B[2:, 2:] = B[:2, :2]
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
224
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   135
#. Find out how to display a grayscale image with proper colors. Hint,
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   136
   use ``?`` on ``imshow``. 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   137
   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   138
   Answer: ``cmap=cm.gray``
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   139
                  
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   140
#. From the image, ``tagore-einstein.png``, 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   141
   a. show only the face of Einstein. 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   142
   b. show only the face of Tagore. 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   143
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   144
   Hint, use ``imread`` to read the image and ``imshow`` to show the
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   145
   image.  Use ``cm.gray`` as ``cmap`` to display the image properly.   
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   146
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   147
   Answer:: 
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   148
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   149
     F = imread('tagore-einstein.png')
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   150
     imshow(F[:210, 20:180], cmap=cm.gray)
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   151
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   152
     F = imread('tagore-einstein.png')
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   153
     imshow(F[30:300, 320:480], cmap=cm.gray)
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   154
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   155
.. #[Puneeth: This question contains answer to previous
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   156
.. question. Shouldn't be shown at the same time.]
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   157
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   158
4e0cdb5cca53 Added questions and other info to accessing-pieces-arrays LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   159