arrays.org
author shantanu <shantanu@fossee.in>
Tue, 30 Mar 2010 19:11:39 +0530
changeset 5 76fe6a48386f
parent 4 4dee50d4804b
child 10 a63d7dcba725
permissions -rw-r--r--
Restored basic-plotting file.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     1
* Arrays
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     2
*** Outline
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     3
***** Introduction
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     4
******* Why do we want to do that?
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     5
******* We shall use arrays (introduced before) for matrices
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     6
******* Arsenal Required
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     7
********* working knowledge of lists
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     8
***** Initializing matrices
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
     9
******* Entering element-wise
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    10
******* using special functions
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    11
***** Accessing and Changing elements
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    12
******* Slicing
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    13
******* Striding
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    14
***** {{Simple operations??}}
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    15
*** Script
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    16
    Welcome to the Tutorial on arrays. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    17
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    18
    As mentioned in [the previous tutorial] arrays are much faster and
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    19
    more efficient. In this tutorial we shall look at creating arrays,
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    20
    accessing elements and changing them. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    21
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    22
    ---
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    23
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    24
    Let's start with creating simple arrays. We've already seen how to
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    25
    convert lists to arrays. Entering an array is similar to that. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    26
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    27
    a = array([5, 8, 10, 13])
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    28
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    29
    We enter a multi-dimensional array this way -
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    30
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    31
    In []: c = array([[11,12,13],
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    32
                      [21,22,23],
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    33
                      [31,32,33]])
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    34
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    35
    To see what c is, we just type c in the prompt. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    36
		      
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    37
    In []: c
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    38
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    39
    To see the dimensions of the array c, we use c.shape
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    40
    In []: c.shape 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    41
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    42
    Now let us look at some special methods of creating an
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    43
    array. There are various functions that allow us to create special
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    44
    arrays. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    45
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    46
    The first one we shall look at is, arange. arange is similar to
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    47
    the range command, except that it returns an array and accepts
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    48
    float arguments. [is range covered?]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    49
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    50
    In []: a = arange(10)
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    51
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    52
    In []: a
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    53
    This is the array we just created. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    54
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    55
    In []: a.shape
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    56
    Note that a is one dimensional and has 10 elements, as expected. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    57
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    58
    We could also use a.shape to change the shape of the array a. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    59
    In []: a.shape = 2,5
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    60
    Note that the total size(number of elements) of new array must 
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    61
    be unchanged. 
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    62
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    63
    We check re-shaped 'a' by
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    64
    In []: a
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    65
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    66
    'ones' function can be used to get an array with all the entries as
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    67
    1s. We pass it the shape of the required array. For ex. 
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    68
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    69
    In []: b = ones((3, 4))
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    70
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    71
    b is 3(cross)4 array with all 1s
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    72
    In []: b 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    73
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    74
    To create an array with all entries as ones, with a shape similar to
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    75
    an already existing array, we use the ones_like function.
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    76
    In []: b = ones_like(a)
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    77
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    78
    zeros and zeros_like are similar commands that can give you arrays
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    79
    with all zeros. empty and empty_like give you empty arrays (arrays
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    80
    with no initialization done.)
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    81
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    82
    {Do an up arrow and quickly show them a couple of examples?}
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    83
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    84
    The identity command can be used to obtain a square array with
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    85
    ones on the main diagonal. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    86
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    87
    In []: identity(3)
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    88
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    89
    To obtain a 2-D array, that is not necessarily square, eye command
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    90
    can be used. Look at the documentation of eye (using eye?) for
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    91
    more info. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    92
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    93
    ---
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    94
    
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
    95
    Now that we have learnt how to create arrays, lets move on to
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    96
    accessing elements and changing them. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    97
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    98
    Let's work with the c, array which we had already created. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
    99
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   100
    In []: c 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   101
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
   102
    Let's say we want to access the element 23 in c(second row 
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
   103
    third column), we say
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   104
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   105
    In []: c[1][2]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   106
    Note that this is similar to accessing an element inside a list of
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   107
    lists. Also, note that counting again starts from 0. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   108
    
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
   109
    Additionally arrays provide a more convenient way to access the 
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
   110
    elements. 
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   111
    In []: c[1, 2]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   112
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   113
    Now, we can also change the element using a simple assignment. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   114
    In []: c[1, 2] = -23
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   115
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   116
    Let's look at accessing more than one elements at a time. We begin
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   117
    with accessing rows. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   118
    In []: c[1] gives us the second row. (counting starts from 0)
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   119
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   120
    To get a column, we use a syntax that is similar to the one used
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   121
    to access a single element. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   122
    In []: c[:,1], gives us the first column. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   123
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   124
    The colon is a way to tell python to get all elements in that
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   125
    dimension from the array. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   126
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   127
    So, we could use a more explicit way to access a row of a
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   128
    In []: c[1,:]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   129
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   130
    We could use the colon to access specific portions of an array. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   131
    In []: c[1,1:2]
4
4dee50d4804b Added changes to array.org file and basic plotting.
Shantanu <shantanu@fossee.in>
parents: 2
diff changeset
   132
    second column, from second row(1) till third(2) and excluding it
2
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   133
    In []: c[1:2,1]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   134
    In []: c[1:2,1:2]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   135
    ...
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   136
    [Oh, by the way this is termed as slicing. :)]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   137
    {How many examples should we show here?}
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   138
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   139
    --- 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   140
    
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   141
    You may have observed the similarity of the semi-colon notation to
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   142
    the range command. As expected, the semi-colon notation also
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   143
    provides a way to specify a jump. This {concept/idea} is termed as
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   144
    Striding. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   145
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   146
    To get every alternate row of c, starting from the first one, we say
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   147
    In []: c[::2,:]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   148
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   149
    To get every alternate row of c, starting from the second one, we
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   150
    say
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   151
    In []: c[1::2,:]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   152
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   153
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   154
    In []: c[:,::2]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   155
    In []: c[::2,::2]
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   156
    {How many examples should we show here?}
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   157
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   158
    ---
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   159
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   160
    We come to the end of this tutorial on arrays. In this tutorial,
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   161
    you've learnt how to create arrays and access, change elements. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   162
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   163
    Thank you. 
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   164
008c0edc6eac Added scripts for session-4 and session-6 of day-1.
Puneeth Chaganti <punchagan@gmail.com>
parents:
diff changeset
   165
*** Notes