|
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 - Creating a 2-dimensional array |
|
48 : In []: a2 = array([[1,2,3,4],[5,6,7,8]]) |
|
49 - Easier method of creating array with consecutive elements. |
|
50 : In []: ar = arange(1,9) |
|
51 * ~reshape()~ method |
|
52 - To reshape an array |
|
53 : In []: ar.reshape(2, 4) |
|
54 : In []: ar.reshape(4, 2) |
|
55 : In []: ar = ar.reshape(2, 4) |
|
56 |
|
57 * Creating ~array~ from ~list~. |
|
58 - ~array()~ method accepts list as argument |
|
59 - Creating a list |
|
60 : In []: l1 = [1, 2, 3, 4] |
|
61 - Creating an array |
|
62 : In []: a3 = array(l1) |
|
63 |
|
64 * Exercise 1 |
|
65 Create a 3-dimensional array of the order (2, 2, 4). |
|
66 |
|
67 * ~.shape~ of array |
|
68 - ~.shape~ |
|
69 To find the shape of the array |
|
70 : In []: a1.shape |
|
71 - ~.shape~ |
|
72 returns a tuple of shape |
|
73 * Exercise 2 |
|
74 Find out the shape of the other arrays(a2, a3, ar) that we have created. |
|
75 * Homogeneous data |
|
76 - All elements in array should be of same type |
|
77 : In []: a4 = array([1,2,3,'a string']) |
|
78 * Implicit type casting |
|
79 : In []: a4 |
|
80 All elements are type casted to string type |
|
81 * ~identity()~, ~zeros()~ methods |
|
82 - ~identity(n)~ |
|
83 Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0. |
|
84 - ~zeros((m, n))~ |
|
85 Creates an ~m X n~ matrix with all elements 0. |
|
86 |
|
87 * Learning exercise |
|
88 - Find out about |
|
89 - ~zeros_like()~ |
|
90 - ~ones()~ |
|
91 - ~ones_like()~ |
|
92 |
|
93 * Array operations |
|
94 - ~a1 * 2~ |
|
95 returns a new array with all elements of ~a1~ multiplied by ~2~. |
|
96 - Similarly ~+~, ~-~ \& ~/~. |
|
97 - ~a1 + 2~ |
|
98 returns a new array with all elements of ~a1~ summed with ~2~. |
|
99 - ~a1 += 2~ |
|
100 adds ~2~ to all elements of array ~a1~. |
|
101 - Similarly ~-=~, ~*=~ \& ~/=~. |
|
102 - ~a1 + a2~ |
|
103 does elements-wise addition. |
|
104 - Similarly ~-~, ~*~ \& ~/~. |
|
105 - ~a1 * a2~ |
|
106 does element-wise multiplication |
|
107 |
|
108 *Note* - array(A) * array(B) does element wise multiplication and not matrix multiplication |
|
109 |
|
110 * Summary |
|
111 In this tutorial we covered, |
|
112 - Basics of arrays |
|
113 - Creating arrays |
|
114 - Arrays from lists |
|
115 - Basic array operations |
|
116 |
|
117 * Thank you! |
|
118 #+begin_latex |
|
119 \begin{block}{} |
|
120 \begin{center} |
|
121 This spoken tutorial has been produced by the |
|
122 \textcolor{blue}{FOSSEE} team, which is funded by the |
|
123 \end{center} |
|
124 \begin{center} |
|
125 \textcolor{blue}{National Mission on Education through \\ |
|
126 Information \& Communication Technology \\ |
|
127 MHRD, Govt. of India}. |
|
128 \end{center} |
|
129 \end{block} |
|
130 #+end_latex |
|
131 |
|
132 |