diff options
author | Jovina | 2011-05-27 12:25:09 +0530 |
---|---|---|
committer | Jovina | 2011-05-27 12:25:09 +0530 |
commit | 8db4f6b46a3c5a461cd563020a670eecb95147aa (patch) | |
tree | a96e8cc4e417bf1c423b711f71ae678a733134f9 /getting_started_with_arrays | |
parent | b72a8b915316d849f3867e3bb9a0b1e163e9a7c4 (diff) | |
download | st-scripts-8db4f6b46a3c5a461cd563020a670eecb95147aa.tar.gz st-scripts-8db4f6b46a3c5a461cd563020a670eecb95147aa.tar.bz2 st-scripts-8db4f6b46a3c5a461cd563020a670eecb95147aa.zip |
Major changes to the scripts & slides of 'Getting started with arrays'.
Diffstat (limited to 'getting_started_with_arrays')
-rw-r--r-- | getting_started_with_arrays/script.rst | 397 | ||||
-rw-r--r-- | getting_started_with_arrays/slides.org | 150 | ||||
-rw-r--r-- | getting_started_with_arrays/slides.tex | 275 |
3 files changed, 440 insertions, 382 deletions
diff --git a/getting_started_with_arrays/script.rst b/getting_started_with_arrays/script.rst index c610e8f..242ac8e 100644 --- a/getting_started_with_arrays/script.rst +++ b/getting_started_with_arrays/script.rst @@ -17,8 +17,6 @@ .. #. getting started with ``ipython``. .. #. getting started with lists. -.. #[sushma: the software required to open the ogg files in windows -.. should also be given in the prerequisites] .. Author: Anoop Jacob Thomas <anoop@fossee.in> Internal Reviewer : Puneeth @@ -30,318 +28,437 @@ Getting started with Arrays =========================== -.. #[Puneeth: Prerequisites and Objectives are missing. Fill them in] +.. L1 -{{{ show the welcome slide }}} +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} -Welcome to the spoken tutorial on getting started with arrays. +.. R1 -{{{ switch to next slide, outline slide }}} +Hello friends and welcome to the spoken tutorial on +'Getting started with arrays'. -In this tutorial, we will learn about the data structure called an array, how to convert -a list into an array, operations on arrays and also why an array is preferred -to lists. +.. L2 -.. #[Puneeth: Fix the grammar above.] +{{{ switch to objectives slide }}} -{{{ switch to next slide on overview of array }}} +.. R2 -Arrays are homogeneous data structures. Unlike lists, arrays cannot have -heterogeneous data elements, that is, they can have only one type of data -as their entries, be them all integers, strings, or maybe floats, but not a mix. +At the end of this tutorial, you will be able to, -.. #[Puneeth: Use multiple short sentences, rather than one long sentence - I would've written something like this. + 1. Create arrays using data. + #. Create arrays from lists. + #. Perform basic array operations. + #. Create identity matrix. + #. Use functions zeros(), zeros_like(), ones(), ones_like(). - Unlike lists, arrays are homogeneous data structures. They can have only - type of data, ....] +.. L3 -Arrays of a given length are comparatively much faster in mathematical -operations than lists of the same length, because of the fact that they are -homogeneous data structures. +{{{ Switch to the pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +tutorial on "Getting started with Lists". + +.. L4 -.. #[Puneeth: For what size of an array is that the comparison? +{{{ switch to next slide on overview of array }}} + +.. R4 + +Arrays are homogeneous data structures. Unlike lists, arrays cannot have +heterogeneous data elements.They can have only one type of data +as their entries, be them all integers, strings, or maybe floats, +but not a mix. -{{{ switch to the next slide, creating arrays }}} +Arrays of a given length are comparatively much faster in mathematical +operations than lists of the same length, because of the fact that they +are homogeneous data structures. Now let us see how to create arrays. -Run your IPython interpreter with ``-pylab`` option, to load the required -modules to work with arrays. -{{{ take terminal and run the following command }}} +.. R5 + +Run your IPython interpreter with ``-pylab`` option, to load the +required modules to work with arrays. + +.. L5 + +{{{ open the terminal and run the following command }}} :: - ipython -pylab + ipython -pylab -.. #[Puneeth: 'I am assuming' doesn't sound right. Ask them to open if it -.. is not open?] +.. R6 To create an array we will use the function ``array()`` as, +.. L6 :: a1 = array([1,2,3,4]) -Notice that we created a one dimensional array here. Also notice the object -we passed to create an array. We passed a list to create an array. - -Now let us see how to create a two dimensional array. Pause the video and try to -solve this. After you solve resume the video to look at the solution. +.. R7 -{{{ switch to next slide, creating two dimensional arrays }}} +Notice that we created a one dimensional array here. Also notice that +the object we passed to create an array is a list. -.. #[Puneeth: I don't think this question can be solved by an average -.. viewer. Questions during the tutorial, should generally be to re-iterate -.. concepts learnt? ] +Now let us see how to create a two dimensional array. -.. #[Puneeth: Also, you didn't even point out that we are converting a -.. list, using the ``array`` function. Bring the later section about -.. converting a list, here. A separate section is not necessary, IMHO.] - -We create two dimensional array by converting a list of lists to an array -as, +We create two dimensional array by converting a list of lists to an +array as, +.. L7 :: a2 = array([[1,2,3,4],[5,6,7,8]]) -.. #[Puneeth: Again, you could explain a bit about the fact that we are -.. converting a list of lists.] +.. R8 Now let us use ``arange()`` function to create the same array as before. +.. L8 :: ar = arange(1,9) - -.. #[Puneeth: say, creating the same array as before. for some time I got -.. confused .] - -And we obtained a one dimensional array with elements from 1 to 8. - -:: - print ar -.. #[Puneeth: be consistent with voice. say, we obtained... or something.] - -And how can we make it a two dimensional array of order 2 by 4? Pause here -and try to do it yourself, try ``ar.tab`` and find a suitable method for -that. +.. R9 -{{{ switch to next slide, reshape() method }}} - -We can use the function ``reshape()`` for that purpose and it can be done -as, +As you can see, we obtained a one dimensional array with elements from +1 to 8. + +Now can we make it a two dimensional array of order 2 by 4? +Yes,we can.For this we will have to use the function ``reshape()``, +.. L9 :: ar.reshape(2,4) ar.reshape(4,2) ar = ar.reshape(2,4) -{{{ switch to next slide, creating array from list}}} +.. R10 + +Hence,we got our two-dimensional array. -Now, let us see how to convert a list object to an array. We define a list -l1 = [1,2,3,4]. To convert l1 into a array use an array command. say a3 = array(l1) +Now, let us see how to convert a list object to an array. We define a +list,say l1 +.. L10 :: l1 = [1,2,3,4] -Now we can convert the list to an array as, +.. R11 + +Now to convert this list to an array,we use the array function as, +.. L11 :: a3 = array(l1) -Pause the video. Solve the exercise on your terminal and resume the video once done - -{{{ switch to the next slide, problem statement of unsolved exercise 1 }}} - -Create a three dimensional array of the shape (2,2,4). - -.. #[Puneeth: s/order/shape or size ?] +.. L12 {{{ switch to the next slide, shape of an array }}} +.. R12 + To find the shape of an array we can use the method ``.shape``, let us check the shape of the arrays we have created so far, -.. #[Puneeth: s/object/method ?] +.. L13 +{{{ Switch to the terminal }}} :: a2.shape -``a2.shape`` object is a tuple, and it returned a tuple (2, 4). +.. R13 + +``a2.shape`` object is a tuple, and it returned a tuple (2, 4).A tuple +is nothing but an ordered list of elements. + +Pause the video here, try out the following exercise and resume the video. + +.. L14 + +{{{ switch to the next slide,exercise 1 }}} -.. #[Puneeth: first show a 2D array, so that it becomes easier to explain. -.. Also, the word ``tuple`` need not be mentioned. ] +.. R14 -{{{ switch to the next slide, unsolved exercise 2 }}} +Find out the shape of the other arrays i.e. a1, a3, ar that we have +created. -Pause the video and Find out the shape of the other -arrays i.e. a1, a3, ar that we have created. +.. L15 -.. #[Puneeth: solution missing.] +{{{ Continue from paused state }}} + +.. R15 It can be done as, + +.. L16 :: a1.shape a3.shape ar.shape -{{{ Array can have only a single type of data }}} - -.. #[Puneeth: I guess, this whole section can be skipped. If you want to -.. keep this, just briefly mention that arrays are homogeneous in the -.. intro, don't explain it there.] +.. R16 Now let us try to create a new array with a mix of elements and see what will happen, +.. L17 :: a4 = array([1,2,3,'a string']) -Well, we would expect an error as it has been previously mentioned that arrays handle -elements with the same datatype, but it didn't raise an error. Let us check the values -in the new array created. In your IPython terminal type, -:: - - a4 +.. R17 -Did you notice it, +Well, we would expect an error as it has been previously mentioned that +arrays handle elements with the same datatype, but it didn't raise an +error. Let us check the values in the new array created. +Type a4 in the terminal, -{{{ switch to next slide, implicit type casting }}} +.. L18 +:: -.. #[Puneeth: typecasting may be unnecessary. (Also too advanced?) an -.. average guy wouldn't use arrays with strings.] + a4 -.. #[Puneeth: You may want to mention that float is the default dtype.] +{{{ highlight all the array elements one by one using mouse movements +accordingly }}} -{{{ highlight all the array elements one by one using mouse movements }}} +.. R18 -all the elements have been implicitly type casted as strings, though our -first three elements were meant to be integers. +Did you notice it, all the elements have been implicitly type casted as +strings, though our first three elements were meant to be integers. +Also,if you have noticed,we got something like 'dtype S8' in the output. +dtype is nothing but the datatype which is the minimum type required +to hold the objects in the sequence. -.. #[Puneeth: when I type a4 it says some ``dtype`` etc. I don't understand -.. what it is, can you explain? ;)] +.. L19 {{{ switch to the next slide, identity & zeros methods }}} -.. #[Puneeth: something needs to motivate this. why are we suddenly talking -.. of an identity matrix?] +.. R19 -Now let us see how to create an identity matrix of a given size, that is a -two-dimensional array in which all the diagonal elements are ones and rest of the -elements are zeros. We can create an identity matrix using the function -``identity()``. +Let us now move on to study functions like zeros() and ones(). +For this ,we will have to create a matrix. +let us see how to create an identity matrix of a given size, that is a +two-dimensional array in which all the diagonal elements are ones and +rest of the elements are zeros. We can create an identity matrix using +the function ``identity()``. The function ``identity()`` takes an integer argument which specifies the size of the desired matrix, +.. L20 :: identity(3) -As you can see the identity function returned a three by three square matrix -with all the diagonal elements as ones and the rest of the elements as zeros. +.. R20 -.. #[Puneeth: You say array here, matrix there -- it's a bit messed up. -.. Clarify, explicitly.] +As you can see the identity function returned a three by three square +matrix with all the diagonal elements as one and the rest of the elements +as zeros. -``zeros()`` function accepts a tuple, which is the order of the array that we -want to create, and it generates an array with all elements as zeros. +``zeros()`` function accepts a tuple, which is the order of the array that +we want to create, and it generates an array with all elements as zeros. -{{{ switch to the next slide, problem statement of solved exercise 1 }}} +Let us create an array of the order four by five with all the elements +zero. We can do it using the method zeros(), -Let us creates an array of the order four by five with all the elements -zero. We can do it using the method zeros, :: +.. L21 +:: zeros((4,5)) +.. R21 + Notice that we passed a tuple to the function zeros. +Pause the video here, try out the following exercise and resume the video. + +.. L22 {{{ switch to next slide, learning exercise }}} +.. R22 + We learned two functions ``identity()`` and ``zeros()``, find out more about the functions ``zeros_like()``, ``ones()``, ``ones_like()``. -{{{ switch to next slide, array operations }}} +.. L23 + +{{{ continue from paused state }}} +{{{ Switch to the terminal }}} + +.. R23 Try the following, first check the value of a1, + +.. L24 :: a1 -``a1`` is a single dimensional array, and now try, +.. R24 + +We see that ``a1`` is a single dimensional array, +Let us now try a1*2 + +.. L25 :: a1 * 2 +.. R25 It returned a new array with all the elements multiplied by 2. +Now let us again check the contents of a1 + +.. L26 :: a1 +.. R26 + note that the value of a1 still remains the same. +.. R27 + Similarly with addition, + +.. L27 :: a1 + 2 + a1 + +.. R28 it returns a new array, with all the elements summed with two. But again notice that the value of a1 has not been changed. -:: - - a1 You may change the value of a1 by simply assigning the newly returned array as, + +.. L28 :: a1 += 2 +.. R29 + Notice the change in elements of a, + +.. L29 :: a -We can use all the mathematical operations with arrays, Now let us try this +.. R30 + +We can use all the mathematical operations with arrays, Now let us try +this + +.. L30 :: a1 = array([1,2,3,4]) a2 = array([1,2,3,4]) a1 + a2 -Returns an array with element by element addition, +.. R31 + +This returns an array with element by element addition + +.. L31 :: a1 * a2 -Returns an array with element by element multiplication, notice that it -does not perform matrix multiplication. +.. R32 + +a1*a2 returns an array with element by element multiplication, notice +that it does not perform matrix multiplication. + +.. L32 + +.. L33 + +{{{ switch to summary slide }}} + +.. R33 + +This brings us to the end of the end of this tutorial.In this tutorial, +we have learnt to, + + 1. Create an array using the ``array()`` function. + #. Convert a list to an array. + #. Perform some basic operations on arrays like addition,multiplication. + #. Use functions like + - .shape + - arrange() + - .reshape + - zeros() & zeros_like() + - ones() & ones_like() + +.. L34 + +{{{Show self assessment questions slide}}} + +.. R34 + +Here are some self assessment questionss for you to solve + +1. ``x = array([1, 2, 3], [5, 6, 7])`` is a valid statement + + - True + - False + + +2. What does the ``ones_like()`` function do? + + (A) Returns an array of ones with the same shape and type as a + given array. + (B) Return a new array of given shape and type, filled with ones. + + Read the statements and answer, + + - Only statement A is correct. + - Only statement B is correct. + - Both statement A and B are correct. + - Both statement A and B are incorrect. + +.. L35 + +{{{solution of self assessment questions on slide}}} + +.. R35 + +And the answers, + +1. False. + The correct way would be to assign the elements as a list of lists + and then convert it to an array +:: -{{{ switch to next slide, summary slide }}} + x = array([[1, 2, 3], [5, 6, 7]]) -So this brings us to the end of this tutorial, in this tutorial we covered -basics of arrays, learned how to create an array, saw how to convert a list -to an array, and basic array operations etc. +2. The function ``ones_like()`` returns an array of ones with the same + shape and type as a given array. -.. #[Puneeth: s/how to create an array/creating an array] +.. L36 + +{{{ switch to thank you slide }}} -{{{ switch to next slide, thank you }}} +.. R36 +Hope you have enjoyed this tutorial and found it useful. Thank you! -.. - Local Variables: - mode: rst - indent-tabs-mode: nil - sentence-end-double-space: nil - fill-column: 75 - End: diff --git a/getting_started_with_arrays/slides.org b/getting_started_with_arrays/slides.org index a5b315f..994d2c2 100644 --- a/getting_started_with_arrays/slides.org +++ b/getting_started_with_arrays/slides.org @@ -18,7 +18,7 @@ #+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, #+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} -#+TITLE: Getting started with arrays +#+TITLE: #+AUTHOR: FOSSEE #+EMAIL: info@fossee.in #+DATE: @@ -29,58 +29,50 @@ #+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc -* Outline - - Arrays - - why arrays over lists - - Creating arrays - - Array operations - +* +#+begin_latex +\begin{center} +\vspace{12pt} +\textcolor{blue}{\huge Getting started with Arrays} +\end{center} +\vspace{18pt} +\begin{center} +\vspace{10pt} +\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ +\vspace{5pt} +\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ +\scriptsize Funded by National Mission on Education through ICT\\ +\scriptsize MHRD,Govt. of India\\ +\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ +\end{center} +#+end_latex +* Objectives + At the end of this tutorial, you will be able to, + + - Create arrays using data. + - Create arrays from lists. + - Perform basic array operations. + - Create identity matrix. + - Use functions zeros(), zeros\_like(), ones(), ones\_like() + + +* Pre-requisite + Spoken tutorial on - + - Getting started with Lists. * Overview of Arrays - Arrays are homogeneous data structures. - elements have to the same data type - Arrays are faster compared to lists - at least /80-100 times/ faster than lists -* Creating Arrays - - Creating a 1-dimensional array - : In []: a1 = array([1, 2, 3, 4]) - ~[1, 2, 3, 4]~ is a list. -* Creating two-dimensional array - - Creating a 2-dimensional array - : In []: a2 = array([[1,2,3,4],[5,6,7,8]]) - here we convert a list of lists to an array making a 2-d array. - - Using ~arange()~ function - : In []: ar = arange(1,9) -* ~reshape()~ method - - To reshape an array - : In []: ar.reshape(2, 4) - : In []: ar.reshape(4, 2) - : In []: ar = ar.reshape(2, 4) - -* Creating ~array~ from ~list~. - - ~array()~ method accepts list as argument - - Creating a list - : In []: l1 = [1, 2, 3, 4] - - Creating an array - : In []: a3 = array(l1) - -* Exercise 1 - Create a 3-dimensional array of the order (2, 2, 4). - * ~.shape~ of array - ~.shape~ To find the shape of the array : In []: a2.shape - ~.shape~ returns a tuple of shape -* Exercise 2 +* Exercise 1 Find out the shape of the other arrays(a1, a3, ar) that we have created. -* Homogeneous data - - All elements in array should be of same type - : In []: a4 = array([1,2,3,'a string']) -* Implicit type casting - : In []: a4 - All elements are type casted to string type * ~identity()~, ~zeros()~ methods - ~identity(n)~ Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0. @@ -88,48 +80,58 @@ Creates an ~m X n~ matrix with all elements 0. * Learning exercise - - Find out about - - ~zeros_like()~ + Find out about + - ~zeros\_like()~ - ~ones()~ - - ~ones_like()~ - -* Array operations - - ~a1 * 2~ - returns a new array with all elements of ~a1~ multiplied by ~2~. - - Similarly ~+~, ~-~ \& ~/~. - - ~a1 + 2~ - returns a new array with all elements of ~a1~ summed with ~2~. - - ~a1 += 2~ - adds ~2~ to all elements of array ~a1~. - - Similarly ~-=~, ~*=~ \& ~/=~. - - ~a1 + a2~ - does elements-wise addition. - - Similarly ~-~, ~*~ \& ~/~. - - ~a1 * a2~ - does element-wise multiplication - - *Note* - array(A) * array(B) does element wise multiplication and not matrix multiplication + - ~ones\_like()~ * Summary - In this tutorial we covered, - - Basics of arrays - - Creating arrays - - Arrays from lists - - Basic array operations - -* Thank you! + In this tutorial, we have learnt to, + - Create an array using the ``array()`` function. + - Convert a list to an array. + - Perform some basic operations on arrays like addition,multiplication. + - Use functions like + - .shape + - arrange() + - .reshape + - zeros() & zeros\_like() + - ones() & ones\_like() + +* Evaluation + 1. ``x = array([1, 2, 3], [5, 6, 7])`` is a valid statement + + - True + - False + + 2. What does the ``ones\_like()`` function do? + + (A) Returns an array of ones with the same shape and type as a + given array. + (B) Return a new array of given shape and type, filled with ones. + + Read the statements and answer, + + - Only statement A is correct. + - Only statement B is correct. + - Both statement A and B are correct. + - Both statement A and B are incorrect. +* Solutions + 1. False + x = array([[1, 2, 3], [5, 6, 7]]) + + 2. Statement A- Returns an array of ones with the same shape and type as a + given array. +* #+begin_latex \begin{block}{} \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the + \textcolor{blue}{\Large THANK YOU!} \end{center} + \end{block} +\begin{block}{} \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. + For more Information, visit our website\\ + \url{http://fossee.in/} \end{center} \end{block} #+end_latex - - diff --git a/getting_started_with_arrays/slides.tex b/getting_started_with_arrays/slides.tex index 7273c59..e35c35e 100644 --- a/getting_started_with_arrays/slides.tex +++ b/getting_started_with_arrays/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-11-07 Sun 15:18 +% Created 2011-05-27 Fri 12:20 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,7 +8,6 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} -\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -24,14 +23,13 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} -\title{Getting started with arrays} +\title{} \author{FOSSEE} \date{} \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} -\maketitle @@ -41,244 +39,185 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} -\begin{frame} -\frametitle{Outline} -\label{sec-1} - -\begin{itemize} -\item Arrays -\begin{itemize} -\item why arrays over lists -\end{itemize} +\begin{frame} -\item Creating arrays -\item Array operations -\end{itemize} +\begin{center} +\vspace{12pt} +\textcolor{blue}{\huge Getting started with Arrays} +\end{center} +\vspace{18pt} +\begin{center} +\vspace{10pt} +\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ +\vspace{5pt} +\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ +\scriptsize Funded by National Mission on Education through ICT\\ +\scriptsize MHRD,Govt. of India\\ +\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ +\end{center} \end{frame} \begin{frame} -\frametitle{Overview of Arrays} +\frametitle{Objectives} \label{sec-2} -\begin{itemize} -\item Arrays are homogeneous data structures. - -\begin{itemize} -\item elements have to the same data type -\end{itemize} + At the end of this tutorial, you will be able to, -\item Arrays are faster compared to lists \begin{itemize} -\item at least \emph{80-100 times} faster than lists -\end{itemize} - +\item Create arrays using data. +\item Create arrays from lists. +\item Perform basic array operations. +\item Create identity matrix. +\item Use functions zeros(), zeros\_like(), ones(), ones\_like() \end{itemize} \end{frame} -\begin{frame}[fragile] -\frametitle{Creating Arrays} +\begin{frame} +\frametitle{Pre-requisite} \label{sec-3} + Spoken tutorial on - + \begin{itemize} -\item Creating a 1-dimensional array +\item Getting started with Lists. \end{itemize} - -\begin{verbatim} - In []: a1 = array([1, 2, 3, 4]) -\end{verbatim} - - \texttt{[1, 2, 3, 4]} is a list. \end{frame} -\begin{frame}[fragile] -\frametitle{Creating two-dimensional array} +\begin{frame} +\frametitle{Overview of Arrays} \label{sec-4} -\begin{itemize} -\item Creating a 2-dimensional array -\end{itemize} -\begin{verbatim} - In []: a2 = array([[1,2,3,4],[5,6,7,8]]) -\end{verbatim} - - here we convert a list of lists to an array making a 2-d array. \begin{itemize} -\item Easier method of creating array with consecutive elements. -\end{itemize} - -\begin{verbatim} - In []: ar = arange(1,9) -\end{verbatim} -\end{frame} -\begin{frame}[fragile] -\frametitle{\texttt{reshape()} method} -\label{sec-5} - +\item Arrays are homogeneous data structures. \begin{itemize} -\item To reshape an array +\item elements have to the same data type \end{itemize} - -\begin{verbatim} - In []: ar.reshape(2, 4) - In []: ar.reshape(4, 2) - In []: ar = ar.reshape(2, 4) -\end{verbatim} -\end{frame} -\begin{frame}[fragile] -\frametitle{Creating \texttt{array} from \texttt{list}.} -\label{sec-6} - +\item Arrays are faster compared to lists \begin{itemize} -\item \texttt{array()} method accepts list as argument -\item Creating a list -\begin{verbatim} - In []: l1 = [1, 2, 3, 4] -\end{verbatim} - -\item Creating an array -\begin{verbatim} - In []: a3 = array(l1) -\end{verbatim} - +\item at least \emph{80-100 times} faster than lists +\end{itemize} \end{itemize} -\end{frame} -\begin{frame} -\frametitle{Exercise 1} -\label{sec-7} - - Create a 3-dimensional array of the order (2, 2, 4). \end{frame} \begin{frame}[fragile] -\frametitle{\texttt{.shape} of array} -\label{sec-8} +\frametitle{\verb~.shape~ of array} +\label{sec-5} + \begin{itemize} -\item \texttt{.shape} +\item \verb~.shape~ To find the shape of the array \begin{verbatim} - In []: a1.shape + In []: a2.shape \end{verbatim} -\item \texttt{.shape} +\item \verb~.shape~ returns a tuple of shape \end{itemize} \end{frame} \begin{frame} -\frametitle{Exercise 2} -\label{sec-9} - - Find out the shape of the other arrays(a2, a3, ar) that we have created. -\end{frame} -\begin{frame}[fragile] -\frametitle{Homogeneous data} -\label{sec-10} - -\begin{itemize} -\item All elements in array should be of same type -\begin{verbatim} - In []: a4 = array([1,2,3,'a string']) -\end{verbatim} - -\end{itemize} -\end{frame} -\begin{frame}[fragile] -\frametitle{Implicit type casting} -\label{sec-11} - -\begin{verbatim} - In []: a4 -\end{verbatim} +\frametitle{Exercise 1} +\label{sec-6} - All elements are type casted to string type + Find out the shape of the other arrays(a1, a3, ar) that we have created. \end{frame} \begin{frame} -\frametitle{\texttt{identity()}, \texttt{zeros()} methods} -\label{sec-12} +\frametitle{\verb~identity()~, \verb~zeros()~ methods} +\label{sec-7} + \begin{itemize} -\item \texttt{identity(n)} +\item \verb~identity(n)~ Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0. -\item \texttt{zeros((m, n))} - Creates an \texttt{m X n} matrix with all elements 0. +\item \verb~zeros((m, n))~ + Creates an \verb~m X n~ matrix with all elements 0. \end{itemize} \end{frame} \begin{frame} \frametitle{Learning exercise} -\label{sec-13} +\label{sec-8} -\begin{itemize} -\item Find out about + Find out about \begin{itemize} -\item \texttt{zeros\_like()} -\item \texttt{ones()} -\item \texttt{ones\_like()} -\end{itemize} - +\item \verb~zeros\_like()~ +\item \verb~ones()~ +\item \verb~ones\_like()~ \end{itemize} \end{frame} \begin{frame} -\frametitle{Array operations} -\label{sec-14} +\frametitle{Summary} +\label{sec-9} -\begin{itemize} -\item \texttt{a1 * 2} - returns a new array with all elements of \texttt{a1} multiplied by \texttt{2}. + In this tutorial, we have learnt to, \begin{itemize} -\item Similarly \texttt{+}, \texttt{-} \& \texttt{/}. -\end{itemize} - -\item \texttt{a1 + 2} - returns a new array with all elements of \texttt{a1} summed with \texttt{2}. -\item \texttt{a1 += 2} - adds \texttt{2} to all elements of array \texttt{a1}. - +\item Create an array using the ``array()`` function. +\item Convert a list to an array. +\item Perform some basic operations on arrays like addition,multiplication. +\item Use functions like \begin{itemize} -\item Similarly \texttt{-=}, \texttt{*=} \& \texttt{/=}. +\item .shape +\item arrange() +\item .reshape +\item zeros() \& zeros\_like() +\item ones() \& ones\_like() \end{itemize} +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Evaluation} +\label{sec-10} -\item \texttt{a1 + a2} - does elements-wise addition. +\begin{enumerate} +\item ``x = array([1, 2, 3], [5, 6, 7])`` is a valid statement \begin{itemize} -\item Similarly \texttt{-}, \texttt{*} \& \texttt{/}. +\item True +\item False \end{itemize} +\vspace{4pt} +\item What does the ``ones\_like()`` function do? + + (A) Returns an array of ones with the same shape and type as a + given array.\\ + (B) Return a new array of given shape and type, filled with ones. +\vspace{6pt} -\item \texttt{a1 * a2} - does element-wise multiplication + Read the statements and answer, +\begin{itemize} +\item Only statement A is correct. +\item Only statement B is correct. +\item Both statement A and B are correct. +\item Both statement A and B are incorrect. \end{itemize} - - - \textbf{Note} - array(A) * array(B) does element wise multiplication and not matrix multiplication +\end{enumerate} \end{frame} \begin{frame} -\frametitle{Summary} -\label{sec-15} +\frametitle{Solutions} +\label{sec-11} - In this tutorial we covered, -\begin{itemize} -\item Basics of arrays -\item Creating arrays -\item Arrays from lists -\item Basic array operations -\end{itemize} + +\begin{enumerate} +\item False\\ + x = array([[1, 2, 3], [5, 6, 7]]) +\vspace{12pt} +\item Statement A - Returns an array of ones with the same shape and type as a + given array. +\end{enumerate} \end{frame} \begin{frame} -\frametitle{Thank you!} -\label{sec-16} \begin{block}{} \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the + \textcolor{blue}{\Large THANK YOU!} \end{center} + \end{block} +\begin{block}{} \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. + For more Information, visit our website\\ + \url{http://fossee.in/} \end{center} \end{block} \end{frame} -\end{document} +\end{document}
\ No newline at end of file |