accessing-pieces-arrays/script.rst
changeset 402 9bf3411b264d
parent 400 2259bd43446a
parent 390 69f285b3a5ed
equal deleted inserted replaced
401:abf092be95ef 402:9bf3411b264d
    14 .. Prerequisites
    14 .. Prerequisites
    15 .. -------------
    15 .. -------------
    16 
    16 
    17 ..   1. getting started with arrays
    17 ..   1. getting started with arrays
    18 
    18 
    19      
    19 .. #[anand: internal reviewer not mentioned]     
    20 .. Author              : Puneeth
    20 .. Author              : Puneeth
    21    Internal Reviewer   : 
    21    Internal Reviewer   : 
    22    External Reviewer   :
    22    External Reviewer   :
    23    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    23    Language Reviewer   : Bhanukiran
       
    24    Checklist OK?       : <06-11-2010, Anand,  OK> [2010-10-05]
    24 
    25 
    25 Script
    26 Script
    26 ------
    27 ------
    27 
    28 
    28 {{{ Screen shows welcome slide }}}
    29 {{{ Screen shows welcome slide }}}
   124 
   125 
   125 ::
   126 ::
   126   
   127   
   127   C[-1] = 0
   128   C[-1] = 0
   128 
   129 
   129 Now, how do we access one column of C? As with accessing
   130 Now, how do we access one column of C? As with accessing individual
   130 individual elements, the column is the second parameter to be
   131 elements, the column is the second parameter to be specified (after
   131 specified (after the comma). The first parameter, is now replaced
   132 the comma). The first parameter, is replaced with a ``:``. This
   132 with a ``:`` to say, that we want all the elements of that
   133 specifies that we want all the elements of that dimension, instead of
   133 dimension, instead of one particular element. We access the third
   134 just one particular element. We access the third column by
   134 column by
       
   135 
   135 
   136 ::
   136 ::
   137   
   137   
   138   C[:, 2]
   138   C[:, 2]
   139 
   139 
   228 
   228 
   229   C[0:3, 2]
   229   C[0:3, 2]
   230 
   230 
   231 to get the elements of rows indexed from 0 to 3, 3 not included
   231 to get the elements of rows indexed from 0 to 3, 3 not included
   232 and column indexed 2. Note that, the index before the colon is
   232 and column indexed 2. Note that, the index before the colon is
   233 included and the index after it is not included, in the slice that
   233 included and the index after it is not included in the slice that
   234 we have obtained. This is very similar to the ``range`` function,
   234 we have obtained. This is very similar to the ``range`` function,
   235 where ``range`` returns a list, in which the upper limit or stop
   235 where ``range`` returns a list, in which the upper limit or stop
   236 value is not included.
   236 value is not included.
   237 
   237 
   238 Now, if we wish to access the elements of row with index 2, and in
   238 Now, if we wish to access the elements of row with index 2, and in
   267 
   267 
   268   C[1:5, 0]
   268   C[1:5, 0]
   269 
   269 
   270 gives the elements [21, 31, 41, 0]
   270 gives the elements [21, 31, 41, 0]
   271 
   271 
   272 Note that when specifying ranges, if you are starting from or
   272 Note that when specifying ranges, if you are starting from the
   273 going up-to the end, the corresponding element may be dropped. So,
   273 beginning or going up-to the end, the corresponding element may be
   274 in the previous example to obtain [11, 21, 31, 41], we could have
   274 dropped. So, in the previous example to obtain [11, 21, 31, 41], we
   275 simply said, 
   275 could have simply said, ::
   276 ::
       
   277 
   276 
   278   C[:4, 0]
   277   C[:4, 0]
   279 
   278 
   280 and 
   279 and 
   281 ::
   280 ::
   321 
   320 
   322 {{ show slide containing Question 5 }} 
   321 {{ show slide containing Question 5 }} 
   323 
   322 
   324 %%5%% Obtain the square in the center of the image.
   323 %%5%% Obtain the square in the center of the image.
   325 
   324 
   326 Following is an exercise that you must do. 
   325 Please, pause the video here. Do the exercises and then continue. 
   327 
   326 
   328 {{ show slide containing Solution 5 }} 
   327 {{ show slide containing Solution 5 }} 
   329 
   328 
   330 ::
   329 ::
   331 
   330 
   381 
   380 
   382   C[::4, 1:4]
   381   C[::4, 1:4]
   383 
   382 
   384 gives the elements [[12, 13, 14], [0, 0, 0]]
   383 gives the elements [[12, 13, 14], [0, 0, 0]]
   385 
   384 
   386 Now, that we know how to stride over an image, we can drop
   385 Now, that we know how to stride over an array, we can drop
   387 alternate rows and columns out of the image in I. 
   386 alternate rows and columns out of the image in I. 
   388 ::
   387 ::
   389 
   388 
   390   I[::2, ::2]
   389   I[::2, ::2]
   391 
   390 
   421 .. 
   420 .. 
   422    Local Variables:
   421    Local Variables:
   423    mode: rst
   422    mode: rst
   424    indent-tabs-mode: nil
   423    indent-tabs-mode: nil
   425    sentence-end-double-space: nil
   424    sentence-end-double-space: nil
   426    fill-column: 75
   425    fill-column: 70
   427    End:
   426    End: