getting_started_with_arrays/slides.org
changeset 522 d33698326409
equal deleted inserted replaced
521:88a01948450d 522:d33698326409
       
     1 #+LaTeX_CLASS: beamer
       
     2 #+LaTeX_CLASS_OPTIONS: [presentation]
       
     3 #+BEAMER_FRAME_LEVEL: 1
       
     4 
       
     5 #+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
       
     6 #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
       
     7 #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
       
     8 
       
     9 #+LaTeX_CLASS: beamer
       
    10 #+LaTeX_CLASS_OPTIONS: [presentation]
       
    11 
       
    12 #+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    13 #+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    14 
       
    15 #+LaTeX_HEADER: \usepackage{listings}
       
    16 
       
    17 #+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    18 #+LaTeX_HEADER:  commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    19 #+LaTeX_HEADER:  showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    20 
       
    21 #+TITLE: Getting started with arrays
       
    22 #+AUTHOR: FOSSEE
       
    23 #+EMAIL: info@fossee.in
       
    24 #+DATE:    
       
    25 
       
    26 #+DESCRIPTION: 
       
    27 #+KEYWORDS: 
       
    28 #+LANGUAGE:  en
       
    29 #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
       
    30 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
       
    31 
       
    32 * Outline
       
    33   - Arrays
       
    34     - why arrays over lists
       
    35   - Creating arrays
       
    36   - Array operations
       
    37 
       
    38 * Overview of Arrays
       
    39   - Arrays are homogeneous data structures.
       
    40     - elements have to the same data type
       
    41   - Arrays are faster compared to lists
       
    42     - at least /80-100 times/ faster than lists
       
    43 
       
    44 * Creating Arrays
       
    45   - Creating a 1-dimensional array
       
    46   : In []: a1 = array([1, 2, 3, 4])
       
    47   ~[1, 2, 3, 4]~ is a list.
       
    48 * Creating two-dimensional array
       
    49   - Creating a 2-dimensional array
       
    50   : In []: a2 = array([[1,2,3,4],[5,6,7,8]])
       
    51   here we convert a list of lists to an array making a 2-d array.
       
    52   - Using ~arange()~ function
       
    53   : In []: ar = arange(1,9)
       
    54 * ~reshape()~ method
       
    55   - To reshape an array
       
    56   : In []: ar.reshape(2, 4)
       
    57   : In []: ar.reshape(4, 2)
       
    58   : In []: ar = ar.reshape(2, 4)
       
    59 
       
    60 * Creating ~array~ from ~list~.
       
    61   - ~array()~ method accepts list as argument
       
    62   - Creating a list
       
    63    : In []: l1 = [1, 2, 3, 4]
       
    64   - Creating an array
       
    65     : In []: a3 = array(l1)
       
    66 
       
    67 * Exercise 1
       
    68   Create a 3-dimensional array of the order (2, 2, 4).
       
    69 
       
    70 * ~.shape~ of array
       
    71   - ~.shape~
       
    72     To find the shape of the array
       
    73     : In []: a2.shape
       
    74   - ~.shape~
       
    75     returns a tuple of shape
       
    76 * Exercise 2
       
    77   Find out the shape of the other arrays(a1, a3, ar) that we have created.
       
    78 * Homogeneous data
       
    79   - All elements in array should be of same type
       
    80     : In []: a4 = array([1,2,3,'a string'])
       
    81 * Implicit type casting 
       
    82    : In []: a4
       
    83     All elements are type casted to string type
       
    84 * ~identity()~, ~zeros()~ methods
       
    85   - ~identity(n)~
       
    86     Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0.
       
    87   - ~zeros((m, n))~
       
    88     Creates an ~m X n~ matrix with all elements 0.
       
    89 
       
    90 * Learning exercise
       
    91   - Find out about
       
    92     - ~zeros_like()~
       
    93     - ~ones()~
       
    94     - ~ones_like()~
       
    95 
       
    96 * Array operations
       
    97   - ~a1 * 2~
       
    98     returns a new array with all elements of ~a1~ multiplied by ~2~.
       
    99     - Similarly ~+~, ~-~ \& ~/~.
       
   100   - ~a1 + 2~
       
   101     returns a new array with all elements of ~a1~ summed with ~2~.
       
   102   - ~a1 += 2~
       
   103     adds ~2~ to all elements of array ~a1~.
       
   104     - Similarly ~-=~, ~*=~ \& ~/=~.
       
   105   - ~a1 + a2~
       
   106     does elements-wise addition.
       
   107     - Similarly ~-~, ~*~ \& ~/~.
       
   108   - ~a1 * a2~
       
   109     does element-wise multiplication
       
   110 
       
   111   *Note* - array(A) * array(B) does element wise multiplication and not matrix multiplication
       
   112 
       
   113 * Summary
       
   114   In this tutorial we covered,
       
   115   - Basics of arrays
       
   116   - Creating arrays
       
   117   - Arrays from lists
       
   118   - Basic array operations
       
   119 
       
   120 * Thank you!
       
   121 #+begin_latex
       
   122   \begin{block}{}
       
   123   \begin{center}
       
   124   This spoken tutorial has been produced by the
       
   125   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   126   \end{center}
       
   127   \begin{center}
       
   128     \textcolor{blue}{National Mission on Education through \\
       
   129       Information \& Communication Technology \\ 
       
   130       MHRD, Govt. of India}.
       
   131   \end{center}  
       
   132   \end{block}
       
   133 #+end_latex
       
   134 
       
   135