getting-started-with-arrays/script.rst
author anand
Sun, 07 Nov 2010 01:18:26 +0530
changeset 390 69f285b3a5ed
parent 319 e8c02b3c51ac
child 393 f99254fc7d70
permissions -rw-r--r--
checklist OK for `accessing pieces arrays`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
     1
.. Objectives
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
     2
.. ----------
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
     3
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     4
.. At the end of this tutorial, you will be able to 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     5
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     6
.. 1. Create arrays using data
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     7
.. #. Create arrays from lists
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     8
.. #. Basic array operations
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
     9
.. #. Creating identity matrix using ``identity()`` function.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
    10
.. #. Learn about ``zeros()``, ``zeros_like()``, ``ones()``,
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
    11
      ``ones_like()`` functions.
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    12
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    13
.. Prerequisites
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    14
.. -------------
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    15
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
    16
..   1. should have ``ipython`` and ``pylab`` installed. 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
    17
..   #. getting started with ``ipython``.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 318
diff changeset
    18
..   #. getting started with lists.
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    19
     
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    20
..  Author: Anoop Jacob Thomas <anoop@fossee.in>
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    21
    Internal Reviewer   : Puneeth 
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    22
    External Reviewer   :
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    23
    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    24
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    25
===========================
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    26
Getting started with Arrays
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    27
===========================
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    28
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    29
.. #[Puneeth: Prerequisites and Objectives are missing. Fill them in]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    30
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    31
{{{ show the welcome slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    32
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    33
Welcome to the spoken tutorial on getting started with arrays.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    34
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    35
{{{ switch to next slide, outline slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    36
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    37
In this tutorial, we will learn about arrays, how to convert a list into an
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    38
array and also why an array is preferred over lists. And array operations.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    39
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    40
.. #[Puneeth: Fix the grammar above.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    41
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    42
{{{ switch to next slide on overview of array }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    43
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    44
Arrays are homogeneous data structures, unlike lists, arrays cannot have
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    45
heterogeneous data elements, that is, it can have only one type of data
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    46
type, either all integers, or strings, or float, and not a mix.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    47
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    48
.. #[Puneeth: Use multiple short sentences, rather than one long sentence
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    49
   I would've written something like this. 
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    50
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    51
   Unlike lists, arrays are homogeneous data structures. They can have only
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    52
   type of data, ....]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    53
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    54
Arrays are really fast in mathematical operations when compared to lists,
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    55
it is at least 80 to 100 times faster than lists.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    56
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    57
.. #[Puneeth: For what size of an array is that the comparison?
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    58
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    59
{{{ switch to the next slide, creating arrays }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    60
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    61
Now let us see how to create arrays.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    62
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    63
I am assuming that you have your IPython interpreter running with the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    64
``-pylab`` option, so that you have the required modules loaded.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    65
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    66
.. #[Puneeth: 'I am assuming' doesn't sound right. Ask them to open if it
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    67
.. is not open?]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    68
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    69
To create an array we will use the function ``array()`` as,
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    70
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    71
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    72
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    73
    a1 = array([1,2,3,4])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    74
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    75
Notice that here we created a one dimensional array. Also notice the object
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    76
we passed to create an array. Now let us see how to create a two
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    77
dimensional array. Pause here and try to do it yourself before looking at
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    78
the solution.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    79
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    80
.. #[Puneeth: I don't think this question can be solved by an average
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    81
.. viewer. Questions during the tutorial, should generally be to re-iterate
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    82
.. concepts learnt? ]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    83
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    84
.. #[Puneeth: Also, you didn't even point out that we are converting a
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    85
.. list, using the ``array`` function. Bring the later section about
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    86
.. converting a list, here. A separate section is not necessary, IMHO.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    87
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    88
This is how we create two dimensional arrays.
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    89
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    90
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    91
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    92
    a2 = array([[1,2,3,4],[5,6,7,8]])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    93
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    94
.. #[Puneeth: Again, you could explain a bit about the fact that we are
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    95
.. converting a list of lists.]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    96
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    97
Let us see an easy method of creating an array with elements 1 to 8.
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
    98
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    99
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   100
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   101
    ar = arange(1,9)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   102
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   103
.. #[Puneeth: say, creating the same array as before. for some time I got
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   104
.. confused .]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   105
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   106
And it created a single dimensional array of elements from 1 to 8.
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   107
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   108
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   109
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   110
    print ar
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   111
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   112
.. #[Puneeth: be consistent with voice. say, we obtained... or something.]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   113
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   114
And how can we make it a two dimensional array of order 2 by 4. Pause here
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   115
and try to do it yourself, try ``ar.tab`` and find a suitable method for
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   116
that.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   117
304
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   118
{{{ switch to next slide, reshape() method }}}
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   119
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   120
We can use the function ``reshape()`` for that purpose and it can be done
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   121
as,
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   122
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   123
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   124
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   125
    ar.reshape(2,4)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   126
    ar.reshape(4,2)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   127
    ar = ar.reshape(2,4)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   128
304
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   129
{{{ switch to next slide, creating array from list}}}
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   130
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   131
Now, let us see how to convert a list object to an array. As you have
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   132
already seen, in both of the previous statements we have passed a list, so
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   133
creating an array can be done so, first let us create a list ``l1``
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   134
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   135
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   136
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   137
    l1 = [1,2,3,4]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   138
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   139
Now we can convert the list to an array as, 
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   140
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   141
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   142
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   143
    a3 = array(l1)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   144
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   145
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   146
{{{ switch to the next slide, problem statement of unsolved exercise 1 }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   147
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   148
Create a three dimensional array of the order (2,2,4).
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   149
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   150
.. #[Puneeth: s/order/shape or size ?]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   151
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   152
{{{ switch to the next slide, shape of an array }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   153
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   154
To find the shape of an array we can use the object ``.shape``, let us
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   155
check the shape of the arrays we have created so far,
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   156
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   157
.. #[Puneeth: s/object/method ?]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   158
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   159
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   160
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   161
    a1.shape
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   162
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   163
``a1.shape`` object is a tuple, and since a1 is a single dimensional array,
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   164
it returned a tuple (4,).
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   165
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   166
.. #[Puneeth: first show a 2D array, so that it becomes easier to explain.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   167
.. Also, the word ``tuple`` need not be mentioned. ]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   168
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   169
{{{ switch to the next slide, unsolved exercise 2 }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   170
304
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   171
Find out the shape of the other arrays that we have created.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   172
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   173
.. #[Puneeth: solution missing.]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   174
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   175
{{{ Array can have only a single type of data }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   176
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   177
.. #[Puneeth: I guess, this whole section can be skipped. If you want to
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   178
.. keep this, just briefly mention that arrays are homogeneous in the
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   179
.. intro, don't explain it there.]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   180
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   181
Now let us try to create a new array with a mix of elements and see what
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   182
will happen,
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   183
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   184
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   185
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   186
    a4 = array([1,2,3,'a string'])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   187
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   188
Well, we expected an error as previously I said that an array can have only
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   189
homogeneous elements, but it didn't give an error. Let us check the values
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   190
in the new array created. In your IPython terminal type, 
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   191
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   192
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   193
    a4
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   194
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   195
Did you notice it,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   196
304
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   197
{{{ switch to next slide, implicit type casting }}}
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   198
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   199
.. #[Puneeth: typecasting may be unnecessary. (Also too advanced?) an
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   200
.. average guy wouldn't use arrays with strings.]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   201
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   202
.. #[Puneeth: You may want to mention that float is the default dtype.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   203
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   204
{{{ highlight all the array elements one by one using mouse movements }}}
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   205
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   206
all the elements have been implicitly type casted as string, though our
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   207
first three elements were integers.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   208
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   209
.. #[Puneeth: when I type a4 it says some ``dtype`` etc. I don't understand
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   210
.. what it is, can you explain? ;)]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   211
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   212
{{{ switch to the next slide, identity & zeros methods }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   213
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   214
.. #[Puneeth: something needs to motivate this. why are we suddenly talking
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   215
.. of an identity matrix?]
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   216
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   217
An identity matrix is a square matrix in which all the diagonal elements
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   218
are one and rest of the elements zero. We can create an identity matrix
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   219
using the method ``identity()``.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   220
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   221
The function ``identity()`` takes an integer argument,
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   222
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   223
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   224
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   225
    identity(3)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   226
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   227
As you can see the identity method returned a three by three square array
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   228
with all the diagonal elements as one and the rest of the elements as zero.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   229
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   230
.. #[Puneeth: You say array here, matrix there -- it's a bit messed up.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   231
.. Clarify, explicitly.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   232
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   233
``zeros()`` function accepts a tuple, which is the order of the array we
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   234
want to create, and it generates an array with all elements zero.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   235
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   236
{{{ switch to the next slide, problem statement of solved exercise 1 }}}
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   237
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   238
Let us creates an array of the order four by five with all the elements
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   239
zero. We can do it using the method zeros, ::
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   240
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   241
    zeros((4,5))
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   242
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   243
Notice that we passed a tuple to the function zeros.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   244
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   245
{{{ switch to next slide, learning exercise }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   246
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   247
We learned two functions ``identity()`` and ``zeros()``, find out more
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   248
about the functions ``zeros_like()``, ``ones()``, ``ones_like()``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   249
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   250
{{{ switch to next slide, array operations }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   251
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   252
Try the following, first check the value of a1,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   253
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   254
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   255
    a1
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   256
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   257
``a1`` is a single dimensional array, and now try,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   258
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   259
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   260
    a1 * 2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   262
It returned a new array with all the elements multiplied by 2.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   263
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   264
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   265
    a1
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   266
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   267
note that the value of a1 still remains the same.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   268
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   269
Similarly with addition,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   270
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   271
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   272
    a1 + 2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   273
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   274
it returns a new array, with all the elements summed with two. But
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   275
again notice that the value of a1 has not been changed.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   276
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   277
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   278
    a1
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   279
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   280
You may change the value of a1 by simply assigning the newly returned
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   281
array as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   282
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   283
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   284
    a1 += 2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   285
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   286
Notice the change in elements of a,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   287
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   288
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   289
    a
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   290
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   291
We can use all the mathematical operations with arrays, Now let us try this
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   292
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   293
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   294
   a1 = array([1,2,3,4])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   295
   a2 = array([1,2,3,4])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   296
   a1 + a2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   297
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   298
Returns an array with element by element addition,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   299
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   300
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   301
    a1 * a2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   302
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   303
Returns an array with element by element multiplication, notice that it
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   304
does not perform matrix multiplication.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   305
304
d98f554bbec0 added slides for getting-started-with-arrays.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   306
{{{ switch to next slide, summary slide }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   307
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   308
So this brings us to the end of this tutorial, in this tutorial we covered
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   309
basics of arrays, how to create an array, converting a list to an array,
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   310
basic array operations etc.
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   311
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   312
.. #[Puneeth: s/how to create an array/creating an array]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   313
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   314
{{{ switch to next slide, thank you }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   315
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   316
Thank you!
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   317
318
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   318
.. 
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   319
   Local Variables:
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   320
   mode: rst
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   321
   indent-tabs-mode: nil
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   322
   sentence-end-double-space: nil
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   323
   fill-column: 75
a45256cc5404 Reviewed getting started with arrays, script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 304
diff changeset
   324
   End: