accessing-pieces-arrays.rst
author amit
Thu, 23 Sep 2010 13:14:31 +0530
changeset 204 65e5e2362bc9
parent 144 476ea1730aee
permissions -rw-r--r--
small change in getting_started_with_lists
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
144
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     1
========
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     2
 Script
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     3
========
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     4
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     5
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     6
{{{ Screen shows welcome slide }}}
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     7
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     8
Welcome to the tutorial on accessing pieces of arrays
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     9
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    10
{{{ Show the outline for this tutorial }}} 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    11
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    12
In this tutorial we shall learn to access individual elements of
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    13
arrays, get rows and columns and other chunks of arrays using
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    14
slicing and striding. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    15
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    16
{{{ switch back to the terminal }}}
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    17
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    18
As usual, we start IPython, using 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    19
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    20
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    21
  ipython -pylab 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    22
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    23
Let us have two arrays, A and C, as the sample arrays that we will
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    24
use to work through this tutorial. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    25
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    26
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    27
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    28
  A = array([12, 23, 34, 45, 56])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    29
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    30
  C = array([[11, 12, 13, 14, 15],
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    31
             [21, 22, 23, 24, 25],
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    32
             [31, 32, 33, 34, 35],
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    33
             [41, 42, 43, 44, 45],
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    34
             [51, 52, 53, 54, 55]])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    35
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    36
Pause the video here and make sure you have the arrays A and C,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    37
typed in correctly.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    38
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    39
Let us begin with the most elementary thing, accessing individual
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    40
elements. Also, let us first do it with the one-dimensional array
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    41
A, and then do the same thing with the two-dimensional array. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    42
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    43
To access, the element 34 in A, we say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    44
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    45
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    46
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    47
  A[1]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    48
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    49
Like lists, indexing starts from 0 in arrays, too. So, 34, the
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    50
third element has the index 2. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    51
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    52
Now, let us access the element 34 from C. To do this, we say
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    53
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    54
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    55
  C[2, 3]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    56
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    57
34 is in the third row and the fourth column, and since indexing
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    58
begins from zero, the row index is 2 and column index is 3. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    59
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    60
Now, that we have accessed one element of the array, let us change
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    61
it. We shall change the 34 to -34 in both A and C. To do this, we
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    62
simply assign the new value after accessing the element. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    63
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    64
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    65
  A[2] = -34
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    66
  C[2, 3] = -34
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    67
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    68
Now that we have accessed and changed a single element, let us
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    69
access and change more than one element at a time; first rows and
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    70
then columns.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    71
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    72
Let us access one row of C, say the third row. We do it by saying, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    73
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    74
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    75
  C[2] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    76
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    77
How do we access the last row of C? We could say,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    78
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    79
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    80
  C[4] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    81
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    82
for the fifth row, or as with lists, use negative indexing and say
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    83
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    84
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    85
  C[-1]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    86
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    87
Now, we could change the last row into all zeros, using either 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    88
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    89
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    90
  C[-1] = [0, 0, 0, 0, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    91
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    92
or 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    93
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    94
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    95
  
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    96
  C[-1] = 0
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    97
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    98
Now, how do we access one column of C? As with accessing
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    99
individual elements, the column is the second parameter to be
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   100
specified (after the comma). The first parameter, is now replaced
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   101
with a ``:`` to say, that we want all the elements of that
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   102
dimension, instead of one particular element. We access the third
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   103
column by
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   104
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   105
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   106
  
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   107
  C[:, 2]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   108
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   109
%%1%% Pause the video here and change the last column of C to
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   110
zeroes and then resume the video.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   111
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   112
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   113
  
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   114
  C[:, -1] = 0
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   115
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   116
Since A is one dimensional, rows and columns of A don't make much
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   117
sense. It has just one row and 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   118
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   119
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   120
  A[:] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   121
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   122
gives the whole of A. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   123
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   124
%%2%% Pause the video here and change ``A`` to ``[11, 12, 13, 14, 15]``
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   125
and then resume the video. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   126
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   127
To change A, we say
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   128
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   129
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   130
  A[:] = [11, 12, 13, 14, 15]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   131
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   132
Now, that we know how to access, rows and columns of an array, we
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   133
shall learn how to access other pieces of an array. For this
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   134
purpose, we will be using image arrays. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   135
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   136
To read an image into an array, we use the ``imread`` command. We
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   137
shall use the image ``squares.png`` present in ``/home/fossee``. We
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   138
shall first navigate to that path in the OS and see what the image
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   139
contains. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   140
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   141
{{{ switch to the browser and show the image }}}
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   142
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   143
{{{ switch back to the ipython terminal }}}
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   144
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   145
Let us now read the data in ``squares.png`` into the array ``I``. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   146
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   147
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   148
  I = imread('/home/fossee/squares.png')
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   149
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   150
We can see the contents of the image, using the command
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   151
``imshow``. We say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   152
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   153
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   154
  imshow(I) 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   155
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   156
to see what has been read into ``I``.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   157
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   158
To see that ``I`` is really, just an array, we say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   159
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   160
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   161
  I 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   162
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   163
at the prompt, and see that an array is displayed. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   164
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   165
To check the dimensions of any array, we can use the method
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   166
shape. We say
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   167
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   168
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   169
  I.shape 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   170
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   171
to get the dimensions of the image. As we can see, ``squares.png``
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   172
has the dimensions of 300x300. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   173
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   174
Our goal for this part of the tutorial would be to get the
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   175
top-left quadrant of the image. To do this, we need to access, a
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   176
few of the rows and a few of the columns of the array. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   177
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   178
To access, the third column of C, we said, ``C[:, 2]``. Essentially,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   179
we are accessing all the rows in column three of C. Now, let us
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   180
modify this to access only the first three rows, of column three
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   181
of C. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   182
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   183
We say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   184
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   185
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   186
  C[0:3, 2]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   187
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   188
to get the elements of rows indexed from 0 to 3, 3 not included
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   189
and column indexed 2. Note that, the index before the colon is
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   190
included and the index after it is not included, in the slice that
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   191
we have obtained. This is very similar to the ``range`` function,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   192
where ``range`` returns a list, in which the upper limit or stop
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   193
value is not included.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   194
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   195
Now, if we wish to access the elements of row with index 2, and in
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   196
columns indexed 0 to 2 (included), we say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   197
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   198
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   199
  C[2, 0:3]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   200
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   201
E%% %% Pause the video here, and first, obtain the elements [22,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   202
23] from C. Then, obtain the elements [11, 21, 31, 41] from
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   203
C. Finally, obtain the elements [21, 31, 41, 0]. Then, resume the
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   204
video.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   205
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   206
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   207
  C[1, 1:3] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   208
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   209
gives the elements [22, 23]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   210
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   211
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   212
  C[0:4, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   213
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   214
gives the elements [11, 21, 31, 41]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   215
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   216
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   217
  C[1:5, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   218
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   219
gives the elements [21, 31, 41, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   220
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   221
Note that when specifying ranges, if you are starting from or
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   222
going up-to the end, the corresponding element may be dropped. So,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   223
in the previous example to obtain [11, 21, 31, 41], we could have
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   224
simply said, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   225
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   226
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   227
  C[:4, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   228
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   229
and 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   230
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   231
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   232
  C[1:, 0]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   233
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   234
gives the elements [21, 31, 41, 0]. If we skip both the indexes,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   235
we get the slice from end to end, as we already know. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   236
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   237
E%% %% Pause the video here. Obtain the elements [[23, 24], [33,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   238
-34]] and then resume the video. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   239
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   240
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   241
  C[1:3, 2:4] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   242
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   243
gives us the elements, [[23, 24], [33, -34]]. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   244
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   245
Now, we wish to obtain the top left quarter of the image. How do
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   246
we go about doing it? Since, we know the shape of the image to be
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   247
300, we know that we need to get the first 150 rows and first 150
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   248
columns. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   249
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   250
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   251
  I[:150, :150]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   252
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   253
gives us the top-left corner of the image. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   254
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   255
We use the ``imshow`` command to see the slice we obtained in the
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   256
form of an image and confirm. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   257
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   258
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   259
  imshow(I[:150, :150])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   260
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   261
E%% %% Pause the video here, and obtain the square in the center
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   262
of the image. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   263
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   264
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   265
  imshow(I[75:225, 75:225])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   266
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   267
Our next goal is to compress the image, using a very simple
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   268
technique to reduce the space that the image takes on disk while
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   269
not compromising too heavily on the image quality. The idea is to
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   270
drop alternate rows and columns of the image and save it. This way
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   271
we will be reducing the data to a fourth of the original data but
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   272
losing only so much of visual information. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   273
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   274
We shall first learn the idea of striding using the smaller array
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   275
C. Suppose we wish to access only the odd rows and columns (first,
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   276
third, fifth). We do this by, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   277
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   278
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   279
  C[0:5:2, 0:5:2]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   280
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   281
if we wish to be explicit, or simply, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   282
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   283
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   284
  C[::2, ::2]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   285
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   286
This is very similar to the step specified to the ``range``
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   287
function. It specifies, the jump or step in which to move, while
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   288
accessing the elements. If no step is specified, a default value
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   289
of 1 is assumed. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   290
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   291
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   292
  C[1::2, ::2] 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   293
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   294
gives the elements, [[21, 23, 0], [41, 43, 0]]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   295
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   296
E%% %% Pause the video here, and obtain the following. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   297
[[12, 0], [42, 0]]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   298
[[12, 13, 14], [0, 0, 0]]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   299
Then, resume the video. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   300
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   301
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   302
  C[::3, 1::3]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   303
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   304
gives the elements [[12, 0], [42, 0]]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   305
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   306
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   307
  C[::4, 1:4]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   308
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   309
gives the elements [[12, 13, 14], [0, 0, 0]]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   310
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   311
Now, that we know how to stride over an image, we can drop
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   312
alternate rows and columns out of the image in I. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   313
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   314
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   315
  I[::2, ::2]
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   316
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   317
To see this image, we say, 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   318
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   319
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   320
  imshow(I[::2, ::2])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   321
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   322
This does not have much data to notice any real difference, but
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   323
notice that the scale has reduced to show that we have dropped
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   324
alternate rows and columns. If you notice carefully, you will be
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   325
able to observe some blurring near the edges. To notice this
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   326
effect more clearly, increase the step to 4. 
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   327
::
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   328
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   329
  imshow(I[::4, ::4])
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   330
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   331
{{{ show summary slide }}}
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   332
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   333
That brings us to the end of this tutorial. In this tutorial, we
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   334
have learnt to access parts of arrays, specifically individual
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   335
elements, rows and columns and larger pieces of arrays. We have
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   336
also learnt how to modify arrays, element wise or in larger
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   337
pieces.
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   338
476ea1730aee Added rst files for scripts.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   339
Thank You!