Renamed all LOs to match with their names in progress.org.
--- a/#symbolics.rst# Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-Symbolics with Sage
--------------------
-
-Hello friends and welcome to this tutorial on symbolics with sage.
-
-
-.. #[Madhu: Sounds more or less like an ad!]
-
-{{{ Part of Notebook with title }}}
-
-.. #[Madhu: Please make your instructions, instructional. While
- recording if I have to read this, think what you are actually
- meaning it will take a lot of time]
-
-We would be using simple mathematical functions on the sage notebook
-for this tutorial.
-
-.. #[Madhu: What is this line doing here. I don't see much use of it]
-
-During the course of the tutorial we will learn
-
-{{{ Part of Notebook with outline }}}
-
-To define symbolic expressions in sage. Use built-in costants and
-function. Integration, differentiation using sage. Defining
-matrices. Defining Symbolic functions. Simplifying and solving
-symbolic expressions and functions.
-
-.. #[Nishanth]: The formatting is all messed up
- First fix the formatting and compile the rst
- The I shall review
-.. #[Madhu: Please make the above items full english sentences, not
- the slides like points. The person recording should be able to
- read your script as is. It can read something like "we will learn
- how to define symbolic expressions in Sage, using built-in ..."]
-
-Using sage we can perform mathematical operations on symbols.
-
-.. #[Madhu: Same mistake with period symbols! Please get the
- punctuation right. Also you may have to rephrase the above
- sentence as "We can use Sage to perform sybmolic mathematical
- operations" or such]
-
-On the sage notebook type::
-
- sin(y)
-
-It raises a name error saying that y is not defined. But in sage we
-can declare y as a symbol using var function.
-
-.. #[Madhu: But is not required]
-::
- var('y')
-
-Now if you type::
-
- sin(y)
-
- sage simply returns the expression .
-
-.. #[Madhu: Why is this line indented? Also full stop. When will you
- learn? Yes we can correct you. But corrections are for you to
- learn. If you don't learn from your mistakes, I don't know what
- to say]
-
-thus now sage treats sin(y) as a symbolic expression . You can use
-this to do a lot of symbolic maths using sage's built-in constants and
-expressions .
-
-.. #[Madhu: "Thus now"? It sounds like Dus and Nou, i.e 10 and 9 in
- Hindi! Full stop again. "a lot" doesn't mean anything until you
- quantify it or give examples.]
-
-Try out
-
-.. #[Madhu: "So let us try" sounds better]
- ::
-
- var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2
-
-Similarly , we can define many algebraic and trigonometric expressions
-using sage .
-
-.. #[Madhu: comma again. Show some more examples?]
-
-
-Sage also provides a few built-in constants which are commonly used in
-mathematics .
-
-example : pi,e,oo , Function n gives the numerical values of all these
- constants.
-
-.. #[Madhu: This doesn't sound like scripts. How will I read this
- while recording. Also if I were recording I would have read your
- third constant as Oh-Oh i.e. double O. It took me at least 30
- seconds to figure out it is infinity]
-
-For instance::
-
- n(e)
-
- 2.71828182845905
-
-gives numerical value of e.
-
-If you look into the documentation of n by doing
-
-.. #[Madhu: "documentation of the function "n"?]
-
-::
- n(<Tab>
-
-You will see what all arguments it can take etc .. It will be very
-helpful if you look at the documentation of all functions introduced
-
-.. #[Madhu: What does etc .. mean in a script?]
-
-Also we can define the no of digits we wish to use in the numerical
-value . For this we have to pass an argument digits. Type
-
-.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to
- use"?]
-::
-
- n(pi, digits = 10)
-
-Apart from the constants sage also has a lot of builtin functions like
-sin,cos,sinh,cosh,log,factorial,gamma,exp,arcsin,arccos,arctan etc ...
-lets try some out on the sage notebook.
-
-.. #[Madhu: Here "a lot" makes sense]
-::
-
- sin(pi/2)
-
- arctan(oo)
-
- log(e,e)
-
-
-Given that we have defined variables like x,y etc .. , We can define
-an arbitrary function with desired name in the following way.::
-
- var('x') function(<tab> {{{ Just to show the documentation
- extend this line }}} function('f',x)
-
-.. #[Madhu: What will the person recording show in the documentation
- without a script for it? Please don't assume recorder can cook up
- things while recording. It is impractical]
-
-Here f is the name of the function and x is the independent variable .
-Now we can define f(x) to be ::
-
- f(x) = x/2 + sin(x)
-
-Evaluating this function f for the value x=pi returns pi/2.::
-
- f(pi)
-
-We can also define functions that are not continuous but defined
-piecewise. We will be using a function which is a parabola between 0
-to 1 and a constant from 1 to 2 . type the following as given on the
-screen
-
-.. #[Madhu: Instead of "We will be using ..." how about "Let us define
- a function ..."]
-::
-
-
- var('x') h(x)=x^2 g(x)=1 f=Piecewise(<Tab> {{{ Just to show the
- documentation extend this line }}}
- f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f
-
-Checking f at 0.4, 1.4 and 3 :: f(0.4) f(1.4) f(3)
-
-.. #[Madhu: Again this doesn't sound like a script]
-
-for f(3) it raises a value not defined in domain error .
-
-
-Apart from operations on expressions and functions one can also use
-them for series .
-
-.. #[Madhu: I am not able to understand this line. "Use them as
-.. series". Use what as series?]
-
-We first define a function f(n) in the way discussed above.::
-
- var('n') function('f', n)
-
-.. #[Madhu: Shouldn't this be on 2 separate lines?]
-
-To sum the function for a range of discrete values of n, we use the
-sage function sum.
-
-For a convergent series , f(n)=1/n^2 we can say ::
-
- var('n') function('f', n)
-
- f(n) = 1/n^2
-
- sum(f(n), n, 1, oo)
-
-For the famous Madhava series :: var('n') function('f', n)
-
-.. #[Madhu: What is this? your double colon says it must be code block
- but where is the indentation and other things. How will the
- recorder know about it?]
-
- f(n) = (-1)^(n-1)*1/(2*n - 1)
-
-This series converges to pi/4. It was used by ancient Indians to
-interpret pi.
-
-.. #[Madhu: I am losing the context. Please add something to bring
- this thing to the context]
-
-For a divergent series, sum would raise a an error 'Sum is
-divergent' ::
-
- var('n')
- function('f', n)
- f(n) = 1/n sum(f(n), n,1, oo)
-
-
-
-
-We can perform simple calculus operation using sage
-
-.. #[Madhu: When you switch to irrelevant topics make sure you use
- some connectors in English like "Moving on let us see how to
- perform simple calculus operations using Sage" or something like
- that]
-For example lets try an expression first ::
-
- diff(x**2+sin(x),x) 2x+cos(x)
-
-The diff function differentiates an expression or a function . Its
-first argument is expression or function and second argument is the
-independent variable .
-
-.. #[Madhu: Full stop, Full stop, Full stop]
-
-We have already tried an expression now lets try a function ::
-
- f=exp(x^2)+arcsin(x) diff(f(x),x)
-
-To get a higher order differentiation we need to add an extra argument
-for order ::
-
- diff(<tab> diff(f(x),x,3)
-
-.. #[Madhu: Please try to be more explicit saying third argument]
-
-in this case it is 3.
-
-
-Just like differentiation of expression you can also integrate them ::
-
- x = var('x') s = integral(1/(1 + (tan(x))**2),x) s
-
-.. #[Madhu: Two separate lines.]
-
-To find the factors of an expression use the "factor" function
-
-.. #[Madhu: See the diff]
-
-::
- factor(<tab> y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) f =
- factor(y)
-
-One can also simplify complicated expression using sage ::
- f.simplify_full()
-
-This simplifies the expression fully . You can also do simplification
-of just the algebraic part and the trigonometric part ::
-
- f.simplify_exp() f.simplify_trig()
-
-.. #[Madhu: Separate lines?]
-
-One can also find roots of an equation by using find_root function::
-
- phi = var('phi') find_root(cos(phi)==sin(phi),0,pi/2)
-
-.. #[Madhu: Separate lines?]
-
-Lets substitute this solution into the equation and see we were
-correct ::
-
- var('phi') f(phi)=cos(phi)-sin(phi)
- root=find_root(f(phi)==0,0,pi/2) f.substitute(phi=root)
-
-.. #[Madhu: Separate lines?]
-
-as we can see the solution is almost equal to zero .
-
-.. #[Madhu: So what?]
-
-We can also define symbolic matrices ::
-
-
-
- var('a,b,c,d') A=matrix([[a,1,0],[0,b,0],[0,c,d]]) A
-
-.. #[Madhu: Why don't you break the lines?]
-
-Now lets do some of the matrix operations on this matrix
-
-.. #[Madhu: Why don't you break the lines? Also how do you connect
- this up? Use some transformation keywords in English]
-::
- A.det() A.inverse()
-
-.. #[Madhu: Why don't you break the lines?]
-
-You can do ::
-
- A.<Tab>
-
-To see what all operations are available
-
-.. #[Madhu: Sounds very abrupt]
-
-{{{ Part of the notebook with summary }}}
-
-So in this tutorial we learnt how to
-
-
-We learnt about defining symbolic expression and functions .
-And some built-in constants and functions .
-Getting value of built-in constants using n function.
-Using Tab to see the documentation.
-Also we learnt how to sum a series using sum function.
-diff() and integrate() for calculus operations .
-Finding roots , factors and simplifying expression using find_root(),
-factor() , simplify_full, simplify_exp , simplify_trig .
-Substituting values in expression using substitute function.
-And finally creating symbolic matrices and performing operation on them .
-
-.. #[Madhu: See what Nishanth is doing. He has written this as
- points. So easy to read out while recording. You may want to
- reorganize like that]
--- a/accessing-pieces-arrays/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-Objective Questions
--------------------
-
-.. A mininum of 8 questions here (along with answers)
-
-1. Given the array, ``A = array([12, 15, 18, 21])``, how do we access
- the element ``18``?
-
- Answer: ``A[2]``
-
-#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
- accessed by ``A[1]``
-
- Answer: ``15``
-
-#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
- accessed by ``A[-3]``?
-
- Answer: ``15``
-
-#. Given the array, ``A = array([12, 15, 18, 21])``, how do you change
- the element ``15`` to ``51``?
-
- Answer: ``A[1] = 51``
-
-#. Given the array, ``A = array([12, 15, 18, 21])``, what is ``A``
- after the execution of the statement ``A[3] = 24``?
-
- Answer: ``array([12, 15, 18, 24])``
-
-#. Given the array, ``A = array([12, 15, 18, 21])``, what is the
- result of the statement, ``A[4] = 24``?
-
- Answer: IndexError: index out of bounds
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do we
- access the element ``18``?
-
- Answer: ``A[0, 0]``
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
- result of ``B[1]``?
-
- Answer: ``array([18, 21])``
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
- result of ``B[1, 1]``?
-
- Answer: ``21``
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, what element
- is accessed by ``B[-1, -2]``?
-
- Answer: ``18``
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do you
- change the element ``15`` to ``51``?
-
- Answer: ``B[0, 1] = 51``
-
-#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
- value of B, after executing, ``B[0] = 0``?
-
- Answer: ``array([[0, 0], [18, 21]])``
-
-#. Given the array,
-
- ::
-
- B = array([[10, 11, 12, 13],
- [20, 21, 22, 23],
- [30, 31, 32, 33],
- [40, 41, 42, 43]])
-
- Obtain the elements, ``[[21, 22], [32, 32]]``
-
- Answer: ``B[1:3, 1:3]``
-
-#. Given the array,
-
- ::
-
- B = array([[10, 11, 12, 13],
- [20, 21, 22, 23],
- [30, 31, 32, 33],
- [40, 41, 42, 43]])
-
- Obtain the elements, ``[[10, 13], [30, 33]]``
-
- Answer: ``B[::2, ::3]``
-
-#. What command is used to read an image file?
-
- a. imshow
- #. imread
- #. imopen
- #. open
-
- Answer: ``imread``
-
-#. If ``P`` is ``array([12, 13, 14, 15])`` then ``P.shape`` gives
- ``(4, 1)``. True or False?
-
- Answer: False
-
-Larger Questions
-----------------
-
-.. A minimum of 2 questions here (along with answers)
-
-1. Given the array,
- ::
-
- B = array([[10, 11, 12, 13],
- [20, 21, 22, 23],
- [30, 31, 32, 33],
- [40, 41, 42, 43]])
-
- Change the array to
- ::
-
- B = array([[10, 11, 10, 11],
- [20, 21, 20, 21],
- [10, 11, 10, 11],
- [20, 21, 20, 21]])
-
- using slicing and striding.
-
- Answer::
-
- B[:2, 2:] = B[:2, :2]
- B[2:, :2] = B[:2, :2]
- B[2:, 2:] = B[:2, :2]
-
-#. Find out how to display a grayscale image with proper colors. Hint,
- use ``?`` on ``imshow``.
-
- Answer: ``cmap=cm.gray``
-
-#. From the image, ``tagore-einstein.png``,
- a. show only the face of Einstein.
- b. show only the face of Tagore.
-
- Hint, use ``imread`` to read the image and ``imshow`` to show the
- image. Use ``cm.gray`` as ``cmap`` to display the image properly.
-
- Answer::
-
- F = imread('tagore-einstein.png')
- imshow(F[:210, 20:180], cmap=cm.gray)
-
- F = imread('tagore-einstein.png')
- imshow(F[30:300, 320:480], cmap=cm.gray)
-
-.. #[Puneeth: This question contains answer to previous
-.. question. Shouldn't be shown at the same time.]
-
-
-
--- a/accessing-pieces-arrays/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-\textbf{Accessing parts of arrays}
-
-\lstinline|C[i-1, j-1]| to access element i, j in C (mxn).
-\lstinline|C[i-1]| to access i^{th} row
-\lstinline|C[:, j-1]| to access j^{th} column
-
-Assigning to accessed elements, changes them.
-
-\lstinline|A[m:n:o]| accesses the rows from \lstinline|m|
-to \lstinline|n| (excluded) in steps of \lstinline|o|
-
-Similarly, \lstinline|C[m:n:o, p:q:r]|
--- a/accessing-pieces-arrays/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,426 +0,0 @@
-.. Objectives
-.. ----------
-
- .. By the end of this tutorial, you will be able to:
-
- .. 1. Access and change individual elements of arrays, both one
- .. dimensional and multi-dimensional.
- .. 2. Access and change rows and columns of arrays.
- .. 3. Access and change other chunks from an array, using slicing
- .. and striding.
- .. 4. Read images into arrays and perform processing on them, using
- .. simple array manipulations.
-
-.. Prerequisites
-.. -------------
-
-.. 1. getting started with arrays
-
-.. #[anand: internal reviewer not mentioned]
-.. Author : Puneeth
- Internal Reviewer :
- External Reviewer :
- Language Reviewer : Bhanukiran
- Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05]
-
-Script
-------
-
-{{{ Screen shows welcome slide }}}
-
-Welcome to the tutorial on accessing pieces of arrays
-
-{{{ Show the outline for this tutorial }}}
-
-In this tutorial we shall learn to access individual elements of
-arrays, get rows and columns and other chunks of arrays using
-slicing and striding.
-
-{{{ switch back to the terminal }}}
-
-As usual, we start IPython, using
-::
-
- ipython -pylab
-
-
-{{ Show the slide with the arrays, A and C }}
-
-Let us have two arrays, A and C, as the sample arrays that we will
-use to work through this tutorial.
-
-::
-
- A = array([12, 23, 34, 45, 56])
-
- C = array([[11, 12, 13, 14, 15],
- [21, 22, 23, 24, 25],
- [31, 32, 33, 34, 35],
- [41, 42, 43, 44, 45],
- [51, 52, 53, 54, 55]])
-
-Pause the video here and make sure you have the arrays A and C,
-typed in correctly.
-
-{{{ Pause the recording and type the arrays A,C }}}
-
-Let us begin with the most elementary thing, accessing individual
-elements. Also, let us first do it with the one-dimensional array
-A, and then do the same thing with the two-dimensional array.
-
-To access, the element 34 in A, we say,
-
-::
-
- A[2]
-
-A of 2, note that we are using square brackets.
-
-Like lists, indexing starts from 0 in arrays, too. So, 34, the
-third element has the index 2.
-
-Now, let us access the element 34 from C. To do this, we say
-::
-
- C[2, 3]
-
-C of 2,3.
-
-34 is in the third row and the fourth column, and since indexing
-begins from zero, the row index is 2 and column index is 3.
-
-Now, that we have accessed one element of the array, let us change
-it. We shall change the 34 to -34 in both A and C. To do this, we
-simply assign the new value after accessing the element.
-::
-
- A[2] = -34
- C[2, 3] = -34
-
-Now that we have accessed and changed a single element, let us
-access and change more than one element at a time; first rows and
-then columns.
-
-Let us access one row of C, say the third row. We do it by saying,
-::
-
- C[2]
-
-How do we access the last row of C? We could say,
-::
-
- C[4]
-
-for the fifth row, or as with lists, use negative indexing and say
-::
-
- C[-1]
-
-Now, we could change the last row into all zeros, using either
-::
-
- C[-1] = [0, 0, 0, 0, 0]
-
-or
-
-::
-
- C[-1] = 0
-
-Now, how do we access one column of C? As with accessing individual
-elements, the column is the second parameter to be specified (after
-the comma). The first parameter, is replaced with a ``:``. This
-specifies that we want all the elements of that dimension, instead of
-just one particular element. We access the third column by
-
-::
-
- C[:, 2]
-
-Following is an exercise that you must do.
-
-{{ show slide containing Question 1}}
-
-%%1%% Change the last column of C to zeroes.
-
-Please, pause the video here. Do the exercises and then continue.
-
-::
-
- C[:, -1] = 0
-
-Since A is one dimensional, rows and columns of A don't make much
-sense. It has just one row and
-::
-
- A[:]
-
-gives the whole of A.
-
-Following is an exercise that you must do.
-
-{{ show slide containing Question 2}}
-
-%%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``.
-
-Please, pause the video here. Do the exercises and then continue.
-
-To change A, we say
-::
-
- A[:] = [11, 12, 13, 14, 15]
-
-Now, that we know how to access, rows and columns of an array, we
-shall learn how to access other pieces of an array. For this
-purpose, we will be using image arrays.
-
-To read an image into an array, we use the ``imread`` command. We
-shall use the image ``squares.png`` present in ``/home/fossee``. We
-shall first navigate to that path in the OS and see what the image
-contains.
-
-{{{ switch to the browser and show the image }}}
-
-{{{ switch back to the ipython terminal }}}
-
-Let us now read the data in ``squares.png`` into the array ``I``.
-::
-
- I = imread('/home/fossee/squares.png')
-
-We can see the contents of the image, using the command
-``imshow``. We say,
-::
-
- imshow(I)
-
-to see what has been read into ``I``. We do not see white and black
-because, ``pylab`` has mapped white and black to different
-colors. This can be changed by using a different colormap.
-
-To see that ``I`` is really, just an array, we say,
-::
-
- I
-
-at the prompt, and see that an array is displayed.
-
-To check the dimensions of any array, we can use ``.shape``. We say
-
-::
-
- I.shape
-
-to get the dimensions of the image. As we can see, ``squares.png``
-has the dimensions of 300x300.
-
-Our goal for this part of the tutorial would be to get the
-top-left quadrant of the image. To do this, we need to access, a
-few of the rows and a few of the columns of the array.
-
-To access, the third column of C, we said, ``C[:, 2]``. Essentially,
-we are accessing all the rows in column three of C. Now, let us
-modify this to access only the first three rows, of column three
-of C.
-
-We say,
-::
-
- C[0:3, 2]
-
-to get the elements of rows indexed from 0 to 3, 3 not included
-and column indexed 2. Note that, the index before the colon is
-included and the index after it is not included in the slice that
-we have obtained. This is very similar to the ``range`` function,
-where ``range`` returns a list, in which the upper limit or stop
-value is not included.
-
-Now, if we wish to access the elements of row with index 2, and in
-columns indexed 0 to 2 (included), we say,
-::
-
- C[2, 0:3]
-
-Following is an exercise that you must do.
-
-{{ show slide containing Question 3 }}
-
-%%3%% First, obtain the elements [22, 23] from C. Then, obtain the
-elements [11, 21, 31, 41] from C. Finally, obtain the elements [21,
-31, 41, 0].
-
-Please, pause the video here. Do the exercises and then continue.
-
-{{ show slide containing Solution 3 }}
-
-::
-
- C[1, 1:3]
-
-gives the elements [22, 23]
-::
-
- C[0:4, 0]
-
-gives the elements [11, 21, 31, 41]
-::
-
- C[1:5, 0]
-
-gives the elements [21, 31, 41, 0]
-
-Note that when specifying ranges, if you are starting from the
-beginning or going up-to the end, the corresponding element may be
-dropped. So, in the previous example to obtain [11, 21, 31, 41], we
-could have simply said, ::
-
- C[:4, 0]
-
-and
-::
-
- C[1:, 0]
-
-gives the elements [21, 31, 41, 0]. If we skip both the indexes,
-we get the slice from end to end, as we already know.
-
-Following is an exercise that you must do.
-
-{{ show slide containing Question 4 }}
-
-%%4%% Obtain the elements [[23, 24], [33, -34]] from C.
-
-Please, pause the video here. Do the exercises and then continue.
-
-{{ show slide containing Solution 4 }}
-
-::
-
- C[1:3, 2:4]
-
-gives us the elements, [[23, 24], [33, -34]].
-
-Now, we wish to obtain the top left quarter of the image. How do
-we go about doing it? Since, we know the shape of the image to be
-300, we know that we need to get the first 150 rows and first 150
-columns.
-::
-
- I[:150, :150]
-
-gives us the top-left corner of the image.
-
-We use the ``imshow`` command to see the slice we obtained in the
-form of an image and confirm.
-::
-
- imshow(I[:150, :150])
-
-Following is an exercise that you must do.
-
-{{ show slide containing Question 5 }}
-
-%%5%% Obtain the square in the center of the image.
-
-Please, pause the video here. Do the exercises and then continue.
-
-{{ show slide containing Solution 5 }}
-
-::
-
- imshow(I[75:225, 75:225])
-
-Our next goal is to compress the image, using a very simple
-technique to reduce the space that the image takes on disk while
-not compromising too heavily on the image quality. The idea is to
-drop alternate rows and columns of the image and save it. This way
-we will be reducing the data to a fourth of the original data but
-losing only so much of visual information.
-
-We shall first learn the idea of striding using the smaller array
-C. Suppose we wish to access only the odd rows and columns (first,
-third, fifth). We do this by,
-::
-
- C[0:5:2, 0:5:2]
-
-if we wish to be explicit, or simply,
-::
-
- C[::2, ::2]
-
-This is very similar to the step specified to the ``range``
-function. It specifies, the jump or step in which to move, while
-accessing the elements. If no step is specified, a default value
-of 1 is assumed.
-::
-
- C[1::2, ::2]
-
-gives the elements, [[21, 23, 0], [41, 43, 0]]
-
-{{ show slide containing Question 6 }}
-
-Following is an exercise that you must do.
-
-%%6%% Obtain the following.
-[[12, 0], [42, 0]]
-[[12, 13, 14], [0, 0, 0]]
-
-Please, pause the video here. Do the exercises and then continue.
-
-{{ show slide containing Solution 6 }}
-
-::
-
- C[::3, 1::3]
-
-gives the elements [[12, 0], [42, 0]]
-::
-
- C[::4, 1:4]
-
-gives the elements [[12, 13, 14], [0, 0, 0]]
-
-Now, that we know how to stride over an array, we can drop
-alternate rows and columns out of the image in I.
-::
-
- I[::2, ::2]
-
-To see this image, we say,
-::
-
- imshow(I[::2, ::2])
-
-This does not have much data to notice any real difference, but
-notice that the scale has reduced to show that we have dropped
-alternate rows and columns. If you notice carefully, you will be
-able to observe some blurring near the edges. To notice this
-effect more clearly, increase the step to 4.
-::
-
- imshow(I[::4, ::4])
-
-{{{ show summary slide }}}
-
-That brings us to the end of this tutorial. In this tutorial, we
-have learnt to access parts of arrays, specifically individual
-elements, rows and columns and larger pieces of arrays. We have
-also learnt how to modify arrays, element wise or in larger
-pieces.
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-Thank you!
-
-..
- Local Variables:
- mode: rst
- indent-tabs-mode: nil
- sentence-end-double-space: nil
- fill-column: 70
- End:
--- a/accessing-pieces-arrays/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Accessing parts of arrays
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- - Manipulating one and multi dimensional arrays
- - Access and change individual elements
- - Access and change rows and columns
- - Slicing and striding on arrays to access chunks
- - Read images into arrays and manipulations
-* Sample Arrays
- #+begin_src python
- In []: A = array([12, 23, 34, 45, 56])
-
- In []: C = array([[11, 12, 13, 14, 15],
- [21, 22, 23, 24, 25],
- [31, 32, 33, 34, 35],
- [41, 42, 43, 44, 45],
- [51, 52, 53, 54, 55]])
-
- #+end_src
-* Question 1
- Change the last column of ~C~ to zeroes.
-* Solution 1
- #+begin_src python
- In []: C[:, -1] = 0
- #+end_src
-* Question 2
- Change ~A~ to ~[11, 12, 13, 14, 15]~.
-* Solution 2
- #+begin_src python
- In []: A[:] = [11, 12, 13, 14, 15]
- #+end_src
-* squares.png
- #+begin_latex
- \begin{center}
- \includegraphics[scale=0.6]{squares}
- \end{center}
- #+end_latex
-* Question 3
- - obtain ~[22, 23]~ from ~C~.
- - obtain ~[11, 21, 31, 41]~ from ~C~.
- - obtain ~[21, 31, 41, 0]~.
-* Solution 3
- #+begin_src python
- In []: C[1, 1:3]
- In []: C[0:4, 0]
- In []: C[1:5, 0]
- #+end_src
-* Question 4
- Obtain ~[[23, 24], [33, -34]]~ from ~C~
-* Solution 4
- #+begin_src python
- In []: C[1:3, 2:4]
- #+end_src
-* Question 5
- Obtain the square in the center of the image
-* Solution 5
- #+begin_src python
- In []: imshow(I[75:225, 75:225])
- #+end_src
-* Question 6
- Obtain the following
- #+begin_src python
- [[12, 0], [42, 0]]
- [[12, 13, 14], [0, 0, 0]]
- #+end_src
-
-* Solution 6
- #+begin_src python
- In []: C[::3, 1::3]
- In []: C[::4, 1:4]
- #+end_src
-* Summary
- You should now be able to --
- - Manipulate single \& multi dimensional arrays
- - Access and change individual elements
- - Access and change rows and columns
- - Slice and stride on arrays
- - Read images into arrays and manipulate them.
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
--- a/accessing-pieces-arrays/slides.org.orig Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Accessing parts of arrays
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- - Manipulating one and multi dimensional arrays
- - Access and change individual elements
- - Access and change rows and columns
- - Slicing and striding on arrays to access chunks
- - Read images into arrays and manipulations
-* Sample Arrays
- #+begin_src python
- In []: A = array([12, 23, 34, 45, 56])
-
- In []: C = array([[11, 12, 13, 14, 15],
- [21, 22, 23, 24, 25],
- [31, 32, 33, 34, 35],
- [41, 42, 43, 44, 45],
- [51, 52, 53, 54, 55]])
-
- #+end_src
-* Question 1
- Change the last column of ~C~ to zeroes.
-* Solution 1
- #+begin_src python
- In []: C[:, -1] = 0
- #+end_src
-* Question 2
- Change ~A~ to ~[11, 12, 13, 14, 15]~.
-* Solution 2
- #+begin_src python
- In []: A[:] = [11, 12, 13, 14, 15]
- #+end_src
-* squares.png
- #+begin_latex
- \begin{center}
- \includegraphics[scale=0.6]{squares}
- \end{center}
- #+end_latex
-* Question 3
- - obtain ~[22, 23]~ from ~C~.
- - obtain ~[11, 21, 31, 41]~ from ~C~.
- - obtain ~[21, 31, 41, 0]~.
-* Solution 3
- #+begin_src python
- In []: C[1, 1:3]
- In []: C[0:4, 0]
- In []: C[1:5, 0]
- #+end_src
-* Question 4
- Obtain ~[[23, 24], [33, -34]]~ from ~C~
-* Solution 4
- #+begin_src python
- In []: C[1:3, 2:4]
- #+end_src
-* Question 5
- Obtain the square in the center of the image
-* Solution 5
- #+begin_src python
- In []: imshow(I[75:225, 75:225])
- #+end_src
-* Question 6
- Obtain the following
- #+begin_src python
- [[12, 0], [42, 0]]
- [[12, 13, 14], [0, 0, 0]]
- #+end_src
-
-* Solution 6
- #+begin_src python
- In []: C[::3, 1::3]
- In []: C[::4, 1:4]
- #+end_src
-* Summary
- You should now be able to --
- - Manipulate single \& multi dimensional arrays
- - Access and change individual elements
- - Access and change rows and columns
- - Slice and stride on arrays
- - Read images into arrays and manipulate them.
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
--- a/accessing-pieces-arrays/slides.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,214 +0,0 @@
-% Created 2010-11-02 Tue 17:47
-\documentclass[presentation]{beamer}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{fixltx2e}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{textcomp}
-\usepackage{marvosym}
-\usepackage{wasysym}
-\usepackage{latexsym}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\tolerance=1000
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-\providecommand{\alert}[1]{\textbf{#1}}
-
-\title{Accessing parts of arrays}
-\author{FOSSEE}
-\date{}
-
-\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-
-\begin{itemize}
-\item Manipulating one and multi dimensional arrays
-\item Access and change individual elements
-\item Access and change rows and columns
-\item Slicing and striding on arrays to access chunks
-\item Read images into arrays and manipulations
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Sample Arrays}
-\label{sec-2}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: A = array([12, 23, 34, 45, 56])
-
-In []: C = array([[11, 12, 13, 14, 15],
- [21, 22, 23, 24, 25],
- [31, 32, 33, 34, 35],
- [41, 42, 43, 44, 45],
- [51, 52, 53, 54, 55]])
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-3}
-
- Change the last column of \texttt{C} to zeroes.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-4}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: C[:, -1] = 0
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-5}
-
- Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 2}
-\label{sec-6}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: A[:] = [11, 12, 13, 14, 15]
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{squares.png}
-\label{sec-7}
-
- \begin{center}
- \includegraphics[scale=0.6]{squares}
- \end{center}
-\end{frame}
-\begin{frame}
-\frametitle{Question 3}
-\label{sec-8}
-
-\begin{itemize}
-\item obtain \texttt{[22, 23]} from \texttt{C}.
-\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}.
-\item obtain \texttt{[21, 31, 41, 0]}.
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 3}
-\label{sec-9}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: C[1, 1:3]
-In []: C[0:4, 0]
-In []: C[1:5, 0]
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 4}
-\label{sec-10}
-
- Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 4}
-\label{sec-11}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: C[1:3, 2:4]
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 5}
-\label{sec-12}
-
- Obtain the square in the center of the image
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 5}
-\label{sec-13}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: imshow(I[75:225, 75:225])
-\end{lstlisting}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Question 6}
-\label{sec-14}
-
- Obtain the following
-\lstset{language=Python}
-\begin{lstlisting}
-[[12, 0], [42, 0]]
-[[12, 13, 14], [0, 0, 0]]
-\end{lstlisting}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 6}
-\label{sec-15}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: C[::3, 1::3]
-In []: C[::4, 1:4]
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-16}
-
- You should now be able to --
-\begin{itemize}
-\item Manipulate single \& multi dimensional arrays
-
-\begin{itemize}
-\item Access and change individual elements
-\item Access and change rows and columns
-\item Slice and stride on arrays
-\end{itemize}
-
-\item Read images into arrays and manipulate them.
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-17}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/accessing-pieces-arrays/slides.tex.orig Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-% Created 2010-11-03 Wed 15:37
-\documentclass[presentation]{beamer}
-\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-\title{Accessing parts of arrays}
-\author{FOSSEE}
-\date{}
-
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-
-\begin{itemize}
-\item Manipulating one and multi dimensional arrays
-\item Access and change individual elements
-\item Access and change rows and columns
-\item Slicing and striding on arrays to access chunks
-\item Read images into arrays and manipulations
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Sample Arrays}
-\label{sec-2}
-
-\begin{verbatim}
-In []: A = array([12, 23, 34, 45, 56])
-
-In []: C = array([[11, 12, 13, 14, 15],
- [21, 22, 23, 24, 25],
- [31, 32, 33, 34, 35],
- [41, 42, 43, 44, 45],
- [51, 52, 53, 54, 55]])
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-3}
-
- Change the last column of \texttt{C} to zeroes.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-4}
-
-\begin{verbatim}
-In []: C[:, -1] = 0
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-5}
-
- Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 2}
-\label{sec-6}
-
-\begin{verbatim}
-In []: A[:] = [11, 12, 13, 14, 15]
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{squares.png}
-\label{sec-7}
-
- \begin{center}
- \includegraphics[scale=0.6]{squares}
- \end{center}
-\end{frame}
-\begin{frame}
-\frametitle{Question 3}
-\label{sec-8}
-
-\begin{itemize}
-\item obtain \texttt{[22, 23]} from \texttt{C}.
-\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}.
-\item obtain \texttt{[21, 31, 41, 0]}.
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 3}
-\label{sec-9}
-
-\begin{verbatim}
-In []: C[1, 1:3]
-In []: C[0:4, 0]
-In []: C[1:5, 0]
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 4}
-\label{sec-10}
-
- Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 4}
-\label{sec-11}
-
-\begin{verbatim}
-In []: C[1:3, 2:4]
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 5}
-\label{sec-12}
-
- Obtain the square in the center of the image
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 5}
-\label{sec-13}
-
-\begin{verbatim}
-In []: imshow(I[75:225, 75:225])
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Question 6}
-\label{sec-14}
-
- Obtain the following
-\begin{verbatim}
-[[12, 0], [42, 0]]
-[[12, 13, 14], [0, 0, 0]]
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 6}
-\label{sec-15}
-
-\begin{verbatim}
-In []: C[::3, 1::3]
-In []: C[::4, 1:4]
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-16}
-
- You should now be able to --
-\begin{itemize}
-\item Manipulate single \& multi dimensional arrays
-
-\begin{itemize}
-\item Access and change individual elements
-\item Access and change rows and columns
-\item Slice and stride on arrays
-\end{itemize}
-
-\item Read images into arrays and manipulate them.
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-17}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
Binary file accessing-pieces-arrays/squares.png has changed
Binary file accessing-pieces-arrays/tagore-einstein.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/questions.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,159 @@
+Objective Questions
+-------------------
+
+.. A mininum of 8 questions here (along with answers)
+
+1. Given the array, ``A = array([12, 15, 18, 21])``, how do we access
+ the element ``18``?
+
+ Answer: ``A[2]``
+
+#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
+ accessed by ``A[1]``
+
+ Answer: ``15``
+
+#. Given the array, ``A = array([12, 15, 18, 21])``, what element is
+ accessed by ``A[-3]``?
+
+ Answer: ``15``
+
+#. Given the array, ``A = array([12, 15, 18, 21])``, how do you change
+ the element ``15`` to ``51``?
+
+ Answer: ``A[1] = 51``
+
+#. Given the array, ``A = array([12, 15, 18, 21])``, what is ``A``
+ after the execution of the statement ``A[3] = 24``?
+
+ Answer: ``array([12, 15, 18, 24])``
+
+#. Given the array, ``A = array([12, 15, 18, 21])``, what is the
+ result of the statement, ``A[4] = 24``?
+
+ Answer: IndexError: index out of bounds
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do we
+ access the element ``18``?
+
+ Answer: ``A[0, 0]``
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
+ result of ``B[1]``?
+
+ Answer: ``array([18, 21])``
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
+ result of ``B[1, 1]``?
+
+ Answer: ``21``
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, what element
+ is accessed by ``B[-1, -2]``?
+
+ Answer: ``18``
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, how do you
+ change the element ``15`` to ``51``?
+
+ Answer: ``B[0, 1] = 51``
+
+#. Given the array, ``B = array([[12, 15], [18, 21]])``, what is the
+ value of B, after executing, ``B[0] = 0``?
+
+ Answer: ``array([[0, 0], [18, 21]])``
+
+#. Given the array,
+
+ ::
+
+ B = array([[10, 11, 12, 13],
+ [20, 21, 22, 23],
+ [30, 31, 32, 33],
+ [40, 41, 42, 43]])
+
+ Obtain the elements, ``[[21, 22], [32, 32]]``
+
+ Answer: ``B[1:3, 1:3]``
+
+#. Given the array,
+
+ ::
+
+ B = array([[10, 11, 12, 13],
+ [20, 21, 22, 23],
+ [30, 31, 32, 33],
+ [40, 41, 42, 43]])
+
+ Obtain the elements, ``[[10, 13], [30, 33]]``
+
+ Answer: ``B[::2, ::3]``
+
+#. What command is used to read an image file?
+
+ a. imshow
+ #. imread
+ #. imopen
+ #. open
+
+ Answer: ``imread``
+
+#. If ``P`` is ``array([12, 13, 14, 15])`` then ``P.shape`` gives
+ ``(4, 1)``. True or False?
+
+ Answer: False
+
+Larger Questions
+----------------
+
+.. A minimum of 2 questions here (along with answers)
+
+1. Given the array,
+ ::
+
+ B = array([[10, 11, 12, 13],
+ [20, 21, 22, 23],
+ [30, 31, 32, 33],
+ [40, 41, 42, 43]])
+
+ Change the array to
+ ::
+
+ B = array([[10, 11, 10, 11],
+ [20, 21, 20, 21],
+ [10, 11, 10, 11],
+ [20, 21, 20, 21]])
+
+ using slicing and striding.
+
+ Answer::
+
+ B[:2, 2:] = B[:2, :2]
+ B[2:, :2] = B[:2, :2]
+ B[2:, 2:] = B[:2, :2]
+
+#. Find out how to display a grayscale image with proper colors. Hint,
+ use ``?`` on ``imshow``.
+
+ Answer: ``cmap=cm.gray``
+
+#. From the image, ``tagore-einstein.png``,
+ a. show only the face of Einstein.
+ b. show only the face of Tagore.
+
+ Hint, use ``imread`` to read the image and ``imshow`` to show the
+ image. Use ``cm.gray`` as ``cmap`` to display the image properly.
+
+ Answer::
+
+ F = imread('tagore-einstein.png')
+ imshow(F[:210, 20:180], cmap=cm.gray)
+
+ F = imread('tagore-einstein.png')
+ imshow(F[30:300, 320:480], cmap=cm.gray)
+
+.. #[Puneeth: This question contains answer to previous
+.. question. Shouldn't be shown at the same time.]
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/quickref.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,12 @@
+\textbf{Accessing parts of arrays}
+
+\lstinline|C[i-1, j-1]| to access element i, j in C (mxn).
+\lstinline|C[i-1]| to access i^{th} row
+\lstinline|C[:, j-1]| to access j^{th} column
+
+Assigning to accessed elements, changes them.
+
+\lstinline|A[m:n:o]| accesses the rows from \lstinline|m|
+to \lstinline|n| (excluded) in steps of \lstinline|o|
+
+Similarly, \lstinline|C[m:n:o, p:q:r]|
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/script.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,426 @@
+.. Objectives
+.. ----------
+
+ .. By the end of this tutorial, you will be able to:
+
+ .. 1. Access and change individual elements of arrays, both one
+ .. dimensional and multi-dimensional.
+ .. 2. Access and change rows and columns of arrays.
+ .. 3. Access and change other chunks from an array, using slicing
+ .. and striding.
+ .. 4. Read images into arrays and perform processing on them, using
+ .. simple array manipulations.
+
+.. Prerequisites
+.. -------------
+
+.. 1. getting started with arrays
+
+.. #[anand: internal reviewer not mentioned]
+.. Author : Puneeth
+ Internal Reviewer :
+ External Reviewer :
+ Language Reviewer : Bhanukiran
+ Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05]
+
+Script
+------
+
+{{{ Screen shows welcome slide }}}
+
+Welcome to the tutorial on accessing pieces of arrays
+
+{{{ Show the outline for this tutorial }}}
+
+In this tutorial we shall learn to access individual elements of
+arrays, get rows and columns and other chunks of arrays using
+slicing and striding.
+
+{{{ switch back to the terminal }}}
+
+As usual, we start IPython, using
+::
+
+ ipython -pylab
+
+
+{{ Show the slide with the arrays, A and C }}
+
+Let us have two arrays, A and C, as the sample arrays that we will
+use to work through this tutorial.
+
+::
+
+ A = array([12, 23, 34, 45, 56])
+
+ C = array([[11, 12, 13, 14, 15],
+ [21, 22, 23, 24, 25],
+ [31, 32, 33, 34, 35],
+ [41, 42, 43, 44, 45],
+ [51, 52, 53, 54, 55]])
+
+Pause the video here and make sure you have the arrays A and C,
+typed in correctly.
+
+{{{ Pause the recording and type the arrays A,C }}}
+
+Let us begin with the most elementary thing, accessing individual
+elements. Also, let us first do it with the one-dimensional array
+A, and then do the same thing with the two-dimensional array.
+
+To access, the element 34 in A, we say,
+
+::
+
+ A[2]
+
+A of 2, note that we are using square brackets.
+
+Like lists, indexing starts from 0 in arrays, too. So, 34, the
+third element has the index 2.
+
+Now, let us access the element 34 from C. To do this, we say
+::
+
+ C[2, 3]
+
+C of 2,3.
+
+34 is in the third row and the fourth column, and since indexing
+begins from zero, the row index is 2 and column index is 3.
+
+Now, that we have accessed one element of the array, let us change
+it. We shall change the 34 to -34 in both A and C. To do this, we
+simply assign the new value after accessing the element.
+::
+
+ A[2] = -34
+ C[2, 3] = -34
+
+Now that we have accessed and changed a single element, let us
+access and change more than one element at a time; first rows and
+then columns.
+
+Let us access one row of C, say the third row. We do it by saying,
+::
+
+ C[2]
+
+How do we access the last row of C? We could say,
+::
+
+ C[4]
+
+for the fifth row, or as with lists, use negative indexing and say
+::
+
+ C[-1]
+
+Now, we could change the last row into all zeros, using either
+::
+
+ C[-1] = [0, 0, 0, 0, 0]
+
+or
+
+::
+
+ C[-1] = 0
+
+Now, how do we access one column of C? As with accessing individual
+elements, the column is the second parameter to be specified (after
+the comma). The first parameter, is replaced with a ``:``. This
+specifies that we want all the elements of that dimension, instead of
+just one particular element. We access the third column by
+
+::
+
+ C[:, 2]
+
+Following is an exercise that you must do.
+
+{{ show slide containing Question 1}}
+
+%%1%% Change the last column of C to zeroes.
+
+Please, pause the video here. Do the exercises and then continue.
+
+::
+
+ C[:, -1] = 0
+
+Since A is one dimensional, rows and columns of A don't make much
+sense. It has just one row and
+::
+
+ A[:]
+
+gives the whole of A.
+
+Following is an exercise that you must do.
+
+{{ show slide containing Question 2}}
+
+%%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``.
+
+Please, pause the video here. Do the exercises and then continue.
+
+To change A, we say
+::
+
+ A[:] = [11, 12, 13, 14, 15]
+
+Now, that we know how to access, rows and columns of an array, we
+shall learn how to access other pieces of an array. For this
+purpose, we will be using image arrays.
+
+To read an image into an array, we use the ``imread`` command. We
+shall use the image ``squares.png`` present in ``/home/fossee``. We
+shall first navigate to that path in the OS and see what the image
+contains.
+
+{{{ switch to the browser and show the image }}}
+
+{{{ switch back to the ipython terminal }}}
+
+Let us now read the data in ``squares.png`` into the array ``I``.
+::
+
+ I = imread('/home/fossee/squares.png')
+
+We can see the contents of the image, using the command
+``imshow``. We say,
+::
+
+ imshow(I)
+
+to see what has been read into ``I``. We do not see white and black
+because, ``pylab`` has mapped white and black to different
+colors. This can be changed by using a different colormap.
+
+To see that ``I`` is really, just an array, we say,
+::
+
+ I
+
+at the prompt, and see that an array is displayed.
+
+To check the dimensions of any array, we can use ``.shape``. We say
+
+::
+
+ I.shape
+
+to get the dimensions of the image. As we can see, ``squares.png``
+has the dimensions of 300x300.
+
+Our goal for this part of the tutorial would be to get the
+top-left quadrant of the image. To do this, we need to access, a
+few of the rows and a few of the columns of the array.
+
+To access, the third column of C, we said, ``C[:, 2]``. Essentially,
+we are accessing all the rows in column three of C. Now, let us
+modify this to access only the first three rows, of column three
+of C.
+
+We say,
+::
+
+ C[0:3, 2]
+
+to get the elements of rows indexed from 0 to 3, 3 not included
+and column indexed 2. Note that, the index before the colon is
+included and the index after it is not included in the slice that
+we have obtained. This is very similar to the ``range`` function,
+where ``range`` returns a list, in which the upper limit or stop
+value is not included.
+
+Now, if we wish to access the elements of row with index 2, and in
+columns indexed 0 to 2 (included), we say,
+::
+
+ C[2, 0:3]
+
+Following is an exercise that you must do.
+
+{{ show slide containing Question 3 }}
+
+%%3%% First, obtain the elements [22, 23] from C. Then, obtain the
+elements [11, 21, 31, 41] from C. Finally, obtain the elements [21,
+31, 41, 0].
+
+Please, pause the video here. Do the exercises and then continue.
+
+{{ show slide containing Solution 3 }}
+
+::
+
+ C[1, 1:3]
+
+gives the elements [22, 23]
+::
+
+ C[0:4, 0]
+
+gives the elements [11, 21, 31, 41]
+::
+
+ C[1:5, 0]
+
+gives the elements [21, 31, 41, 0]
+
+Note that when specifying ranges, if you are starting from the
+beginning or going up-to the end, the corresponding element may be
+dropped. So, in the previous example to obtain [11, 21, 31, 41], we
+could have simply said, ::
+
+ C[:4, 0]
+
+and
+::
+
+ C[1:, 0]
+
+gives the elements [21, 31, 41, 0]. If we skip both the indexes,
+we get the slice from end to end, as we already know.
+
+Following is an exercise that you must do.
+
+{{ show slide containing Question 4 }}
+
+%%4%% Obtain the elements [[23, 24], [33, -34]] from C.
+
+Please, pause the video here. Do the exercises and then continue.
+
+{{ show slide containing Solution 4 }}
+
+::
+
+ C[1:3, 2:4]
+
+gives us the elements, [[23, 24], [33, -34]].
+
+Now, we wish to obtain the top left quarter of the image. How do
+we go about doing it? Since, we know the shape of the image to be
+300, we know that we need to get the first 150 rows and first 150
+columns.
+::
+
+ I[:150, :150]
+
+gives us the top-left corner of the image.
+
+We use the ``imshow`` command to see the slice we obtained in the
+form of an image and confirm.
+::
+
+ imshow(I[:150, :150])
+
+Following is an exercise that you must do.
+
+{{ show slide containing Question 5 }}
+
+%%5%% Obtain the square in the center of the image.
+
+Please, pause the video here. Do the exercises and then continue.
+
+{{ show slide containing Solution 5 }}
+
+::
+
+ imshow(I[75:225, 75:225])
+
+Our next goal is to compress the image, using a very simple
+technique to reduce the space that the image takes on disk while
+not compromising too heavily on the image quality. The idea is to
+drop alternate rows and columns of the image and save it. This way
+we will be reducing the data to a fourth of the original data but
+losing only so much of visual information.
+
+We shall first learn the idea of striding using the smaller array
+C. Suppose we wish to access only the odd rows and columns (first,
+third, fifth). We do this by,
+::
+
+ C[0:5:2, 0:5:2]
+
+if we wish to be explicit, or simply,
+::
+
+ C[::2, ::2]
+
+This is very similar to the step specified to the ``range``
+function. It specifies, the jump or step in which to move, while
+accessing the elements. If no step is specified, a default value
+of 1 is assumed.
+::
+
+ C[1::2, ::2]
+
+gives the elements, [[21, 23, 0], [41, 43, 0]]
+
+{{ show slide containing Question 6 }}
+
+Following is an exercise that you must do.
+
+%%6%% Obtain the following.
+[[12, 0], [42, 0]]
+[[12, 13, 14], [0, 0, 0]]
+
+Please, pause the video here. Do the exercises and then continue.
+
+{{ show slide containing Solution 6 }}
+
+::
+
+ C[::3, 1::3]
+
+gives the elements [[12, 0], [42, 0]]
+::
+
+ C[::4, 1:4]
+
+gives the elements [[12, 13, 14], [0, 0, 0]]
+
+Now, that we know how to stride over an array, we can drop
+alternate rows and columns out of the image in I.
+::
+
+ I[::2, ::2]
+
+To see this image, we say,
+::
+
+ imshow(I[::2, ::2])
+
+This does not have much data to notice any real difference, but
+notice that the scale has reduced to show that we have dropped
+alternate rows and columns. If you notice carefully, you will be
+able to observe some blurring near the edges. To notice this
+effect more clearly, increase the step to 4.
+::
+
+ imshow(I[::4, ::4])
+
+{{{ show summary slide }}}
+
+That brings us to the end of this tutorial. In this tutorial, we
+have learnt to access parts of arrays, specifically individual
+elements, rows and columns and larger pieces of arrays. We have
+also learnt how to modify arrays, element wise or in larger
+pieces.
+
+{{{ Show the "sponsored by FOSSEE" slide }}}
+
+This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+
+Hope you have enjoyed and found it useful.
+Thank you!
+
+..
+ Local Variables:
+ mode: rst
+ indent-tabs-mode: nil
+ sentence-end-double-space: nil
+ fill-column: 70
+ End:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/slides.org Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,123 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Accessing parts of arrays
+#+AUTHOR: FOSSEE
+#+EMAIL:
+#+DATE:
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+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
+ - Manipulating one and multi dimensional arrays
+ - Access and change individual elements
+ - Access and change rows and columns
+ - Slicing and striding on arrays to access chunks
+ - Read images into arrays and manipulations
+* Sample Arrays
+ #+begin_src python
+ In []: A = array([12, 23, 34, 45, 56])
+
+ In []: C = array([[11, 12, 13, 14, 15],
+ [21, 22, 23, 24, 25],
+ [31, 32, 33, 34, 35],
+ [41, 42, 43, 44, 45],
+ [51, 52, 53, 54, 55]])
+
+ #+end_src
+* Question 1
+ Change the last column of ~C~ to zeroes.
+* Solution 1
+ #+begin_src python
+ In []: C[:, -1] = 0
+ #+end_src
+* Question 2
+ Change ~A~ to ~[11, 12, 13, 14, 15]~.
+* Solution 2
+ #+begin_src python
+ In []: A[:] = [11, 12, 13, 14, 15]
+ #+end_src
+* squares.png
+ #+begin_latex
+ \begin{center}
+ \includegraphics[scale=0.6]{squares}
+ \end{center}
+ #+end_latex
+* Question 3
+ - obtain ~[22, 23]~ from ~C~.
+ - obtain ~[11, 21, 31, 41]~ from ~C~.
+ - obtain ~[21, 31, 41, 0]~.
+* Solution 3
+ #+begin_src python
+ In []: C[1, 1:3]
+ In []: C[0:4, 0]
+ In []: C[1:5, 0]
+ #+end_src
+* Question 4
+ Obtain ~[[23, 24], [33, -34]]~ from ~C~
+* Solution 4
+ #+begin_src python
+ In []: C[1:3, 2:4]
+ #+end_src
+* Question 5
+ Obtain the square in the center of the image
+* Solution 5
+ #+begin_src python
+ In []: imshow(I[75:225, 75:225])
+ #+end_src
+* Question 6
+ Obtain the following
+ #+begin_src python
+ [[12, 0], [42, 0]]
+ [[12, 13, 14], [0, 0, 0]]
+ #+end_src
+
+* Solution 6
+ #+begin_src python
+ In []: C[::3, 1::3]
+ In []: C[::4, 1:4]
+ #+end_src
+* Summary
+ You should now be able to --
+ - Manipulate single \& multi dimensional arrays
+ - Access and change individual elements
+ - Access and change rows and columns
+ - Slice and stride on arrays
+ - Read images into arrays and manipulate them.
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/slides.org.orig Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,123 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Accessing parts of arrays
+#+AUTHOR: FOSSEE
+#+EMAIL:
+#+DATE:
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+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
+ - Manipulating one and multi dimensional arrays
+ - Access and change individual elements
+ - Access and change rows and columns
+ - Slicing and striding on arrays to access chunks
+ - Read images into arrays and manipulations
+* Sample Arrays
+ #+begin_src python
+ In []: A = array([12, 23, 34, 45, 56])
+
+ In []: C = array([[11, 12, 13, 14, 15],
+ [21, 22, 23, 24, 25],
+ [31, 32, 33, 34, 35],
+ [41, 42, 43, 44, 45],
+ [51, 52, 53, 54, 55]])
+
+ #+end_src
+* Question 1
+ Change the last column of ~C~ to zeroes.
+* Solution 1
+ #+begin_src python
+ In []: C[:, -1] = 0
+ #+end_src
+* Question 2
+ Change ~A~ to ~[11, 12, 13, 14, 15]~.
+* Solution 2
+ #+begin_src python
+ In []: A[:] = [11, 12, 13, 14, 15]
+ #+end_src
+* squares.png
+ #+begin_latex
+ \begin{center}
+ \includegraphics[scale=0.6]{squares}
+ \end{center}
+ #+end_latex
+* Question 3
+ - obtain ~[22, 23]~ from ~C~.
+ - obtain ~[11, 21, 31, 41]~ from ~C~.
+ - obtain ~[21, 31, 41, 0]~.
+* Solution 3
+ #+begin_src python
+ In []: C[1, 1:3]
+ In []: C[0:4, 0]
+ In []: C[1:5, 0]
+ #+end_src
+* Question 4
+ Obtain ~[[23, 24], [33, -34]]~ from ~C~
+* Solution 4
+ #+begin_src python
+ In []: C[1:3, 2:4]
+ #+end_src
+* Question 5
+ Obtain the square in the center of the image
+* Solution 5
+ #+begin_src python
+ In []: imshow(I[75:225, 75:225])
+ #+end_src
+* Question 6
+ Obtain the following
+ #+begin_src python
+ [[12, 0], [42, 0]]
+ [[12, 13, 14], [0, 0, 0]]
+ #+end_src
+
+* Solution 6
+ #+begin_src python
+ In []: C[::3, 1::3]
+ In []: C[::4, 1:4]
+ #+end_src
+* Summary
+ You should now be able to --
+ - Manipulate single \& multi dimensional arrays
+ - Access and change individual elements
+ - Access and change rows and columns
+ - Slice and stride on arrays
+ - Read images into arrays and manipulate them.
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/slides.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,214 @@
+% Created 2010-11-02 Tue 17:47
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Accessing parts of arrays}
+\author{FOSSEE}
+\date{}
+
+\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+
+\begin{itemize}
+\item Manipulating one and multi dimensional arrays
+\item Access and change individual elements
+\item Access and change rows and columns
+\item Slicing and striding on arrays to access chunks
+\item Read images into arrays and manipulations
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Sample Arrays}
+\label{sec-2}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: A = array([12, 23, 34, 45, 56])
+
+In []: C = array([[11, 12, 13, 14, 15],
+ [21, 22, 23, 24, 25],
+ [31, 32, 33, 34, 35],
+ [41, 42, 43, 44, 45],
+ [51, 52, 53, 54, 55]])
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\label{sec-3}
+
+ Change the last column of \texttt{C} to zeroes.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-4}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: C[:, -1] = 0
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 2}
+\label{sec-5}
+
+ Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 2}
+\label{sec-6}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: A[:] = [11, 12, 13, 14, 15]
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{squares.png}
+\label{sec-7}
+
+ \begin{center}
+ \includegraphics[scale=0.6]{squares}
+ \end{center}
+\end{frame}
+\begin{frame}
+\frametitle{Question 3}
+\label{sec-8}
+
+\begin{itemize}
+\item obtain \texttt{[22, 23]} from \texttt{C}.
+\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}.
+\item obtain \texttt{[21, 31, 41, 0]}.
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 3}
+\label{sec-9}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: C[1, 1:3]
+In []: C[0:4, 0]
+In []: C[1:5, 0]
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 4}
+\label{sec-10}
+
+ Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 4}
+\label{sec-11}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: C[1:3, 2:4]
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 5}
+\label{sec-12}
+
+ Obtain the square in the center of the image
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 5}
+\label{sec-13}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: imshow(I[75:225, 75:225])
+\end{lstlisting}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Question 6}
+\label{sec-14}
+
+ Obtain the following
+\lstset{language=Python}
+\begin{lstlisting}
+[[12, 0], [42, 0]]
+[[12, 13, 14], [0, 0, 0]]
+\end{lstlisting}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 6}
+\label{sec-15}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: C[::3, 1::3]
+In []: C[::4, 1:4]
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-16}
+
+ You should now be able to --
+\begin{itemize}
+\item Manipulate single \& multi dimensional arrays
+
+\begin{itemize}
+\item Access and change individual elements
+\item Access and change rows and columns
+\item Slice and stride on arrays
+\end{itemize}
+
+\item Read images into arrays and manipulate them.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-17}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/accessing_parts_of_arrays/slides.tex.orig Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,199 @@
+% Created 2010-11-03 Wed 15:37
+\documentclass[presentation]{beamer}
+\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+\title{Accessing parts of arrays}
+\author{FOSSEE}
+\date{}
+
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+
+\begin{itemize}
+\item Manipulating one and multi dimensional arrays
+\item Access and change individual elements
+\item Access and change rows and columns
+\item Slicing and striding on arrays to access chunks
+\item Read images into arrays and manipulations
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Sample Arrays}
+\label{sec-2}
+
+\begin{verbatim}
+In []: A = array([12, 23, 34, 45, 56])
+
+In []: C = array([[11, 12, 13, 14, 15],
+ [21, 22, 23, 24, 25],
+ [31, 32, 33, 34, 35],
+ [41, 42, 43, 44, 45],
+ [51, 52, 53, 54, 55]])
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\label{sec-3}
+
+ Change the last column of \texttt{C} to zeroes.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-4}
+
+\begin{verbatim}
+In []: C[:, -1] = 0
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 2}
+\label{sec-5}
+
+ Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 2}
+\label{sec-6}
+
+\begin{verbatim}
+In []: A[:] = [11, 12, 13, 14, 15]
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{squares.png}
+\label{sec-7}
+
+ \begin{center}
+ \includegraphics[scale=0.6]{squares}
+ \end{center}
+\end{frame}
+\begin{frame}
+\frametitle{Question 3}
+\label{sec-8}
+
+\begin{itemize}
+\item obtain \texttt{[22, 23]} from \texttt{C}.
+\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}.
+\item obtain \texttt{[21, 31, 41, 0]}.
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 3}
+\label{sec-9}
+
+\begin{verbatim}
+In []: C[1, 1:3]
+In []: C[0:4, 0]
+In []: C[1:5, 0]
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 4}
+\label{sec-10}
+
+ Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 4}
+\label{sec-11}
+
+\begin{verbatim}
+In []: C[1:3, 2:4]
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 5}
+\label{sec-12}
+
+ Obtain the square in the center of the image
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 5}
+\label{sec-13}
+
+\begin{verbatim}
+In []: imshow(I[75:225, 75:225])
+\end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Question 6}
+\label{sec-14}
+
+ Obtain the following
+\begin{verbatim}
+[[12, 0], [42, 0]]
+[[12, 13, 14], [0, 0, 0]]
+\end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 6}
+\label{sec-15}
+
+\begin{verbatim}
+In []: C[::3, 1::3]
+In []: C[::4, 1:4]
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-16}
+
+ You should now be able to --
+\begin{itemize}
+\item Manipulate single \& multi dimensional arrays
+
+\begin{itemize}
+\item Access and change individual elements
+\item Access and change rows and columns
+\item Slice and stride on arrays
+\end{itemize}
+
+\item Read images into arrays and manipulate them.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-17}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}
Binary file accessing_parts_of_arrays/squares.png has changed
Binary file accessing_parts_of_arrays/tagore-einstein.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/additional_features_of_ipython/questions.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,134 @@
+Objective Questions
+-------------------
+
+ 1. How do you retrieve the recent 5 commands
+
+ a. ``%hist``
+ #. ``%hist -5``
+ #. ``%hist 5``
+ #. ``%hist 5-10``
+
+ Answer: ``%hist 5``
+
+ 2. If there were 20 commands typed and ``%hist`` is used. How many commands
+ will be displayed.
+
+ a. 10
+ #. 20
+ #. 21
+ #. 19
+
+ Answer: 21
+
+.. #[Amit: I really don't get the question below]
+
+ 3. is ``%hist`` considered as a command
+
+ a. True
+ #. False
+
+ Answer: True
+
+ 4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
+
+ a. ``%hist 20 50``
+ #. ``%hist 19 50``
+ #. ``%hist 19 51``
+ #. ``%hist 21 50``
+
+ Answer: ``%hist 20 50``
+
+ 5. What does the ``%hist 2 5 7`` command do
+
+ a. lists the second, fifth and seventh commands
+ #. lists the commands from 2 to 5 and the seventh command
+ #. raises an error
+ #. lists the commands 2 to 7
+
+ Answer: raises an error
+
+ 6. How many commands are displayed when lot of commands were typed and
+ ``%hist`` is used.
+.. #[Amit: Ok something wrong with the question.
+.. Recommend : What is the default maximum number of commands %hist can show ]
+
+ a. 20
+ #. 10
+ #. 50
+ #. 40
+
+ Answer: 40
+
+ 7. How do you save the lines 2 3 4 5 7 9 10 11
+
+ a. ``%save filepath 2-5 7 9-11``
+ #. ``%save filepath 2-11``
+ #. ``%save filepath``
+ #. ``%save 2-5 7 9 10 11``
+
+ Answer: ``%save filepath 2-5 7 9-11``
+
+ 8. You are working in /home/user. Where is the file saved when you do
+ ``%save hello.py 1-3``
+
+ a. /home/user/hello.py
+ #. /hello.py
+ #. /home/hello.py
+ #. /home/user/ipython/hello.py
+
+ Answer: /home/user/hello.py
+
+ 9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
+ which order
+
+ a. 2 3 4 5 7 1
+ #. 1 2 3 4 5 6 7
+ #. 2 5 7 1
+ #. 1 2 5 7
+
+ Answer: a
+
+10. What happens when ``%save filepath line_numbers`` is used and a file
+ already exists in that path.
+
+ a. It is overwritten
+ #. The commands are added to the file
+ #. It raises an error
+ #. A prompt to confirm overwriting is displayed
+
+ Answer: A prompt to confirm overwriting is displayed
+
+ 11. Read through the documentation of ``%hist`` and find its alternative name
+
+ Answer: ``%history``
+
+ 12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
+
+ a. Yes
+ #. No
+
+ Answer: Yes
+
+ 13. The file hello.py contains only one command ``x = x + 1``. What happens
+ when you do ``%run hello.py``
+
+ Answer: Raises a nameerror
+
+ 14. The file hello.py contains only one command ``x = x + 1``. If value of x
+ is 5 and what does ``%run -i hello.py`` do.
+
+ a. raises an error
+ #. increments value of x by 1
+ #. Does nothing
+
+ Answer: increments the value of x by 1
+
+
+Long Answer questions :
+-----------------------
+
+1. Question 1
+2. Question 2
+
+.. #[Amit: I think long answer questions for this script are
+.. not possible. Please add if someone comes up with any]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/additional_features_of_ipython/quickref.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,15 @@
+accessing history:\\
+{\ex \lstinline| \%hist|}
+
+accessing particular line of history:\\
+{\ex \lstinline| \%hist line_number|}
+
+accessing particular range of history:\\
+{\ex \lstinline| \%hist start_line stop_line|}
+
+saving history to a file:\\
+{\ex \lstinline| \%save file_path line_numbers|}
+
+running a script:\\
+{\ex \lstinline| \%run -i file_path|}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/additional_features_of_ipython/script.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,219 @@
+.. Objectives
+.. ----------
+
+.. By the end of this tutorial you will be able to
+
+.. #. Retrieve your ipython history
+.. #. View a part of the history
+.. #. Save a part of your history to a file.
+.. #. Run a script from within ipython
+
+
+.. Prerequisites
+.. -------------
+
+.. 1. Embellishing Plots
+
+.. Author : Nishanth Amuluru
+ Internal Reviewer : Amit
+ External Reviewer :
+ Language Reviewer : Bhanukiran
+ Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05]
+
+Script
+------
+
+Hello friends and welcome to the tutorial on Additional Features of IPython
+
+{{{ Show the slide containing title }}}
+
+{{{ Show the slide containing the outline slide }}}
+
+In this tutorial, we shall look at additional features of IPython that help us
+to retreive the commands that we type on the interpreter and then save them
+into a file and run it.
+
+Let us start ipython with pylab loaded, by typing
+::
+
+ $ ipython -pylab
+
+on the terminal
+
+{{{ shift to terminal and type ipython -pylab }}}
+
+We shall first make a plot and then view the history and save it.
+::
+
+ x = linspace(-2*pi, 2*pi, 100)
+ plot(x, xsinx(x))
+
+xsin(x) is actually x * sin(x)
+::
+
+ plot(x, x*sin(x))
+ plot(x, sin(x))
+ xlabel("x")
+ ylabel("$f(x)$")
+ title("x and xsin")
+
+We now have the plot. Let us look at the commands that we have typed in. The
+history can be retreived by using =%hist= command. Type
+::
+
+ %hist
+
+As you can see, it displays a list of recent commands that we typed. Every
+command has a number in front, to specify in which order and when it was typed.
+
+Please note that there is a % sign before the hist command. This implies that
+%hist is a command that is specific to IPython and not available in the vannila
+Python interpreter. These type of commands are called as magic commands.
+
+Also note that, the =%hist= itself is a command and is displayed as the most
+recent command. We should not that anything we type in is stored as history,
+irrespective of whether it is command or an error or IPython magic command.
+
+If we want only the recent 5 commands to be displayed, we pass the number as an argument
+to =%hist= command. Hence
+::
+
+ %hist 5
+
+displays the recent 5 commands, inclusive of the =%hist= command.
+The default number is 40.
+
+{{{ Pause here and try out the following exercises }}}
+
+%% 1 %% Read through the documentation of %hist and find out how to
+ list all the commands between 5 and 10
+
+{{{ continue from paused state }}}
+
+As we can see from =%hist= documentation,
+::
+
+ %hist 5 10
+
+displays the commands from 5 to 10
+
+Now that we have the history, we would like to save the required line of code
+from history. This is possible by using the =%save= command.
+
+Before we do that, let us first look at history and identify what lines of code we require.Type
+::
+
+ %hist
+
+
+{{{ point to the lines }}}
+
+The first command is linspace. But second command is a command that gave us an
+error. Hence we do not need second command. The commands from third to sixth are
+required. The seventh command although is correct, we do not need it since we
+are setting the title correctly in the eigthth command.
+
+So we need first third to sixth and the eigthth command for our program.
+Hence the syntax of =%save= is
+::
+
+ %save /home/fossee/plot_script.py 1 3-6 8
+
+{{{ point to the output of the command }}}
+
+The command saves first and then third to sixth and eighth lines of code into
+the specified file.
+
+The first argument to %save is the path of file to save the commands and the
+arguments there after are the commands to be saved in the given order.
+
+{{{ goto the file and open it and show it }}}
+
+{{{ Pause here and try out the following exercises }}}
+
+%% 2 %% Change the label on y-axis to "y" and save the lines of code
+ accordingly
+
+{{{ continue from paused state }}}
+
+we use the command =ylabel= on interpreter as
+::
+
+ ylabel("y")
+
+and then do
+::
+
+ %save /home/fossee/example_plot.py 1 3-6 10
+
+Now that we have the required lines of code in a file, let us learn how to run
+the file as a python script.
+
+We use the IPython magic command =%run= to do this. Type
+::
+
+ %run -i /home/fossee/plot_script.py
+
+The script runs but we do not see the plot. This happens because when we are running
+a script and we are not in interactive mode anymore.
+
+Hence on your terminal type
+::
+
+ show()
+
+to show the plot.
+
+{{{ Pause here and try out the following exercises }}}
+
+%% 3 %% Use %hist and %save and create a script that has show in it and run it
+ to produce and show the plot.
+
+
+{{{ continue from paused state }}}
+
+We first look at the history using
+::
+
+ %hist 20
+
+Then save the script using
+::
+
+ %save /home/fossee/show_included.py 1 3-6 8 10 13
+ %run -i /home/fossee/show_included.py
+ show()
+
+We get the desired plot.
+
+The reason for including a -i after run is to tell the interpreter that if any
+name is not found in script, search for it in the interpreter. Hence all these
+sin, plot, pi and show which are not available in script, are taken from the
+interpreter and used to run the script.
+
+{{{ Pause here and try out the following exercises }}}
+
+%% 4 %% Run the script without using the -i option. Do you find any difference?
+
+{{{ continue from paused state }}}
+
+We see that it raises NameError saying that the name linspace is not found.
+
+{{{ Show summary slide }}}
+
+This brings us to the end of the tutorial.
+we have looked at
+
+ * Retreiving history using =%hist= command
+ * Vieweing only a part of history by passing an argument to %hist
+ * saving the required lines of code in required order using %save
+ * using %run -i command to run the saved script
+
+{{{ Show the "sponsored by FOSSEE" slide }}}
+
+
+This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+
+Hope you have enjoyed and found it useful.
+Thank You!
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/additional_features_of_ipython/slides.org Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,90 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER:\usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Additional Features of =ipython=
+#+AUTHOR: FOSSEE
+#+EMAIL:
+#+DATE:
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+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
+ + Retrieving ipython history
+ + Viewing a part of the history
+ + Saving (relevant) parts of the history to a file
+ + Running a script from within ipython
+* Question 1
+ Read through the documentation of ~%hist~ and find out how to list
+ all the commands between 5 and 10
+* Solution 1
+ #+begin_src python
+ In []: %hist 5 10
+ #+end_src
+* Question 2
+ Change the label on y-axis to "y" and save the lines of code
+ accordingly
+* Solution 2
+ #+begin_src python
+ In []: ylabel("y")
+ In []: %save /home/fossee/example_plot.py 1 3-6 10
+ #+end_src
+* Question 3
+ Use =%hist= and =%save= and create a script that has show in it and
+ run it to produce and show the plot.
+
+* Solution 3
+ #+begin_src python
+ In []: %hist 20
+
+ In []: %save /home/fossee/show_included.py 1 3-6 8 10 13
+ In []: %run -i /home/fossee/show_included.py
+ #+end_src
+* Question 4
+ Run the script without using the -i option. Do you find any
+ difference?
+* Solution 4
+ We see that it raises ~NameError~ saying the name ~linspace~ is not
+ found.
+* Summary
+ + Retreiving history using =%hist= command
+ + Vieweing only a part of history by passing an argument to %hist
+ + Saving the required lines of code in required order using %save
+ + Using %run -i command to run the saved script
+
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/additional_features_of_ipython/slides.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,149 @@
+% Created 2010-10-10 Sun 17:30
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Additional Features of \texttt{ipython}}
+\author{FOSSEE}
+\date{}
+
+\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+
+\begin{itemize}
+\item Retrieving ipython history
+\item Viewing a part of the history
+\item Saving (relevant) parts of the history to a file
+\item Running a script from within ipython
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\label{sec-2}
+
+ Read through the documentation of \texttt{\%hist} and find out how to list
+ all the commands between 5 and 10
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-3}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: %hist 5 10
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 2}
+\label{sec-4}
+
+ Change the label on y-axis to ``y'' and save the lines of code
+ accordingly
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 2}
+\label{sec-5}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: ylabel("y")
+In []: %save /home/fossee/example_plot.py 1 3-6 10
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 3}
+\label{sec-6}
+
+ Use \texttt{\%hist} and \texttt{\%save} and create a script that has show in it and
+ run it to produce and show the plot.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 3}
+\label{sec-7}
+
+\lstset{language=Python}
+\begin{lstlisting}
+In []: %hist 20
+
+In []: %save /home/fossee/show_included.py 1 3-6 8 10 13
+In []: %run -i /home/fossee/show_included.py
+\end{lstlisting}
+\end{frame}
+\begin{frame}
+\frametitle{Question 4}
+\label{sec-8}
+
+ Run the script without using the -i option. Do you find any
+ difference?
+\end{frame}
+\begin{frame}
+\frametitle{Solution 4}
+\label{sec-9}
+
+ We see that it raises \texttt{NameError} saying the name \texttt{linspace} is not
+ found.
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-10}
+
+\begin{itemize}
+\item Retreiving history using \texttt{\%hist} command
+\item Vieweing only a part of history by passing an argument to \%hist
+\item Saving the required lines of code in required order using \%save
+\item Using \%run -i command to run the saved script
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-11}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}
--- a/additional_ipython/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-Objective Questions
--------------------
-
- 1. How do you retrieve the recent 5 commands
-
- a. ``%hist``
- #. ``%hist -5``
- #. ``%hist 5``
- #. ``%hist 5-10``
-
- Answer: ``%hist 5``
-
- 2. If there were 20 commands typed and ``%hist`` is used. How many commands
- will be displayed.
-
- a. 10
- #. 20
- #. 21
- #. 19
-
- Answer: 21
-
-.. #[Amit: I really don't get the question below]
-
- 3. is ``%hist`` considered as a command
-
- a. True
- #. False
-
- Answer: True
-
- 4. how do you retreive the commands from 20 to 50 (inclusive of 20 and 50)
-
- a. ``%hist 20 50``
- #. ``%hist 19 50``
- #. ``%hist 19 51``
- #. ``%hist 21 50``
-
- Answer: ``%hist 20 50``
-
- 5. What does the ``%hist 2 5 7`` command do
-
- a. lists the second, fifth and seventh commands
- #. lists the commands from 2 to 5 and the seventh command
- #. raises an error
- #. lists the commands 2 to 7
-
- Answer: raises an error
-
- 6. How many commands are displayed when lot of commands were typed and
- ``%hist`` is used.
-.. #[Amit: Ok something wrong with the question.
-.. Recommend : What is the default maximum number of commands %hist can show ]
-
- a. 20
- #. 10
- #. 50
- #. 40
-
- Answer: 40
-
- 7. How do you save the lines 2 3 4 5 7 9 10 11
-
- a. ``%save filepath 2-5 7 9-11``
- #. ``%save filepath 2-11``
- #. ``%save filepath``
- #. ``%save 2-5 7 9 10 11``
-
- Answer: ``%save filepath 2-5 7 9-11``
-
- 8. You are working in /home/user. Where is the file saved when you do
- ``%save hello.py 1-3``
-
- a. /home/user/hello.py
- #. /hello.py
- #. /home/hello.py
- #. /home/user/ipython/hello.py
-
- Answer: /home/user/hello.py
-
- 9. Which lines are saved by the command ``%save filepath 2-5 7 1`` and in
- which order
-
- a. 2 3 4 5 7 1
- #. 1 2 3 4 5 6 7
- #. 2 5 7 1
- #. 1 2 5 7
-
- Answer: a
-
-10. What happens when ``%save filepath line_numbers`` is used and a file
- already exists in that path.
-
- a. It is overwritten
- #. The commands are added to the file
- #. It raises an error
- #. A prompt to confirm overwriting is displayed
-
- Answer: A prompt to confirm overwriting is displayed
-
- 11. Read through the documentation of ``%hist`` and find its alternative name
-
- Answer: ``%history``
-
- 12. Are ``%run /home/user/saved.py`` and ``%run /home/user/saved`` the same
-
- a. Yes
- #. No
-
- Answer: Yes
-
- 13. The file hello.py contains only one command ``x = x + 1``. What happens
- when you do ``%run hello.py``
-
- Answer: Raises a nameerror
-
- 14. The file hello.py contains only one command ``x = x + 1``. If value of x
- is 5 and what does ``%run -i hello.py`` do.
-
- a. raises an error
- #. increments value of x by 1
- #. Does nothing
-
- Answer: increments the value of x by 1
-
-
-Long Answer questions :
------------------------
-
-1. Question 1
-2. Question 2
-
-.. #[Amit: I think long answer questions for this script are
-.. not possible. Please add if someone comes up with any]
--- a/additional_ipython/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-accessing history:\\
-{\ex \lstinline| \%hist|}
-
-accessing particular line of history:\\
-{\ex \lstinline| \%hist line_number|}
-
-accessing particular range of history:\\
-{\ex \lstinline| \%hist start_line stop_line|}
-
-saving history to a file:\\
-{\ex \lstinline| \%save file_path line_numbers|}
-
-running a script:\\
-{\ex \lstinline| \%run -i file_path|}
-
--- a/additional_ipython/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-.. Objectives
-.. ----------
-
-.. By the end of this tutorial you will be able to
-
-.. #. Retrieve your ipython history
-.. #. View a part of the history
-.. #. Save a part of your history to a file.
-.. #. Run a script from within ipython
-
-
-.. Prerequisites
-.. -------------
-
-.. 1. Embellishing Plots
-
-.. Author : Nishanth Amuluru
- Internal Reviewer : Amit
- External Reviewer :
- Language Reviewer : Bhanukiran
- Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05]
-
-Script
-------
-
-Hello friends and welcome to the tutorial on Additional Features of IPython
-
-{{{ Show the slide containing title }}}
-
-{{{ Show the slide containing the outline slide }}}
-
-In this tutorial, we shall look at additional features of IPython that help us
-to retreive the commands that we type on the interpreter and then save them
-into a file and run it.
-
-Let us start ipython with pylab loaded, by typing
-::
-
- $ ipython -pylab
-
-on the terminal
-
-{{{ shift to terminal and type ipython -pylab }}}
-
-We shall first make a plot and then view the history and save it.
-::
-
- x = linspace(-2*pi, 2*pi, 100)
- plot(x, xsinx(x))
-
-xsin(x) is actually x * sin(x)
-::
-
- plot(x, x*sin(x))
- plot(x, sin(x))
- xlabel("x")
- ylabel("$f(x)$")
- title("x and xsin")
-
-We now have the plot. Let us look at the commands that we have typed in. The
-history can be retreived by using =%hist= command. Type
-::
-
- %hist
-
-As you can see, it displays a list of recent commands that we typed. Every
-command has a number in front, to specify in which order and when it was typed.
-
-Please note that there is a % sign before the hist command. This implies that
-%hist is a command that is specific to IPython and not available in the vannila
-Python interpreter. These type of commands are called as magic commands.
-
-Also note that, the =%hist= itself is a command and is displayed as the most
-recent command. We should not that anything we type in is stored as history,
-irrespective of whether it is command or an error or IPython magic command.
-
-If we want only the recent 5 commands to be displayed, we pass the number as an argument
-to =%hist= command. Hence
-::
-
- %hist 5
-
-displays the recent 5 commands, inclusive of the =%hist= command.
-The default number is 40.
-
-{{{ Pause here and try out the following exercises }}}
-
-%% 1 %% Read through the documentation of %hist and find out how to
- list all the commands between 5 and 10
-
-{{{ continue from paused state }}}
-
-As we can see from =%hist= documentation,
-::
-
- %hist 5 10
-
-displays the commands from 5 to 10
-
-Now that we have the history, we would like to save the required line of code
-from history. This is possible by using the =%save= command.
-
-Before we do that, let us first look at history and identify what lines of code we require.Type
-::
-
- %hist
-
-
-{{{ point to the lines }}}
-
-The first command is linspace. But second command is a command that gave us an
-error. Hence we do not need second command. The commands from third to sixth are
-required. The seventh command although is correct, we do not need it since we
-are setting the title correctly in the eigthth command.
-
-So we need first third to sixth and the eigthth command for our program.
-Hence the syntax of =%save= is
-::
-
- %save /home/fossee/plot_script.py 1 3-6 8
-
-{{{ point to the output of the command }}}
-
-The command saves first and then third to sixth and eighth lines of code into
-the specified file.
-
-The first argument to %save is the path of file to save the commands and the
-arguments there after are the commands to be saved in the given order.
-
-{{{ goto the file and open it and show it }}}
-
-{{{ Pause here and try out the following exercises }}}
-
-%% 2 %% Change the label on y-axis to "y" and save the lines of code
- accordingly
-
-{{{ continue from paused state }}}
-
-we use the command =ylabel= on interpreter as
-::
-
- ylabel("y")
-
-and then do
-::
-
- %save /home/fossee/example_plot.py 1 3-6 10
-
-Now that we have the required lines of code in a file, let us learn how to run
-the file as a python script.
-
-We use the IPython magic command =%run= to do this. Type
-::
-
- %run -i /home/fossee/plot_script.py
-
-The script runs but we do not see the plot. This happens because when we are running
-a script and we are not in interactive mode anymore.
-
-Hence on your terminal type
-::
-
- show()
-
-to show the plot.
-
-{{{ Pause here and try out the following exercises }}}
-
-%% 3 %% Use %hist and %save and create a script that has show in it and run it
- to produce and show the plot.
-
-
-{{{ continue from paused state }}}
-
-We first look at the history using
-::
-
- %hist 20
-
-Then save the script using
-::
-
- %save /home/fossee/show_included.py 1 3-6 8 10 13
- %run -i /home/fossee/show_included.py
- show()
-
-We get the desired plot.
-
-The reason for including a -i after run is to tell the interpreter that if any
-name is not found in script, search for it in the interpreter. Hence all these
-sin, plot, pi and show which are not available in script, are taken from the
-interpreter and used to run the script.
-
-{{{ Pause here and try out the following exercises }}}
-
-%% 4 %% Run the script without using the -i option. Do you find any difference?
-
-{{{ continue from paused state }}}
-
-We see that it raises NameError saying that the name linspace is not found.
-
-{{{ Show summary slide }}}
-
-This brings us to the end of the tutorial.
-we have looked at
-
- * Retreiving history using =%hist= command
- * Vieweing only a part of history by passing an argument to %hist
- * saving the required lines of code in required order using %save
- * using %run -i command to run the saved script
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-Thank You!
-
--- a/additional_ipython/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER:\usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Additional Features of =ipython=
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- + Retrieving ipython history
- + Viewing a part of the history
- + Saving (relevant) parts of the history to a file
- + Running a script from within ipython
-* Question 1
- Read through the documentation of ~%hist~ and find out how to list
- all the commands between 5 and 10
-* Solution 1
- #+begin_src python
- In []: %hist 5 10
- #+end_src
-* Question 2
- Change the label on y-axis to "y" and save the lines of code
- accordingly
-* Solution 2
- #+begin_src python
- In []: ylabel("y")
- In []: %save /home/fossee/example_plot.py 1 3-6 10
- #+end_src
-* Question 3
- Use =%hist= and =%save= and create a script that has show in it and
- run it to produce and show the plot.
-
-* Solution 3
- #+begin_src python
- In []: %hist 20
-
- In []: %save /home/fossee/show_included.py 1 3-6 8 10 13
- In []: %run -i /home/fossee/show_included.py
- #+end_src
-* Question 4
- Run the script without using the -i option. Do you find any
- difference?
-* Solution 4
- We see that it raises ~NameError~ saying the name ~linspace~ is not
- found.
-* Summary
- + Retreiving history using =%hist= command
- + Vieweing only a part of history by passing an argument to %hist
- + Saving the required lines of code in required order using %save
- + Using %run -i command to run the saved script
-
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
--- a/additional_ipython/slides.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-% Created 2010-10-10 Sun 17:30
-\documentclass[presentation]{beamer}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{fixltx2e}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{textcomp}
-\usepackage{marvosym}
-\usepackage{wasysym}
-\usepackage{latexsym}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\tolerance=1000
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-\providecommand{\alert}[1]{\textbf{#1}}
-
-\title{Additional Features of \texttt{ipython}}
-\author{FOSSEE}
-\date{}
-
-\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-
-\begin{itemize}
-\item Retrieving ipython history
-\item Viewing a part of the history
-\item Saving (relevant) parts of the history to a file
-\item Running a script from within ipython
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-2}
-
- Read through the documentation of \texttt{\%hist} and find out how to list
- all the commands between 5 and 10
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-3}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: %hist 5 10
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-4}
-
- Change the label on y-axis to ``y'' and save the lines of code
- accordingly
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 2}
-\label{sec-5}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: ylabel("y")
-In []: %save /home/fossee/example_plot.py 1 3-6 10
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 3}
-\label{sec-6}
-
- Use \texttt{\%hist} and \texttt{\%save} and create a script that has show in it and
- run it to produce and show the plot.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 3}
-\label{sec-7}
-
-\lstset{language=Python}
-\begin{lstlisting}
-In []: %hist 20
-
-In []: %save /home/fossee/show_included.py 1 3-6 8 10 13
-In []: %run -i /home/fossee/show_included.py
-\end{lstlisting}
-\end{frame}
-\begin{frame}
-\frametitle{Question 4}
-\label{sec-8}
-
- Run the script without using the -i option. Do you find any
- difference?
-\end{frame}
-\begin{frame}
-\frametitle{Solution 4}
-\label{sec-9}
-
- We see that it raises \texttt{NameError} saying the name \texttt{linspace} is not
- found.
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-10}
-
-\begin{itemize}
-\item Retreiving history using \texttt{\%hist} command
-\item Vieweing only a part of history by passing an argument to \%hist
-\item Saving the required lines of code in required order using \%save
-\item Using \%run -i command to run the saved script
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-11}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/advanced-features-functions/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-Objective Questions
--------------------
-
-.. A mininum of 8 questions here (along with answers)
-
-1. All arguments of a function cannot have default values. True or
- False?
-
- Answer: False
-
-#. When calling a function, the arguments
-
- 1. should always be in the order in which they are defined.
- #. can be in any order
- #. only keyword arguments can be in any order, but should be called
- at the beginning.
- #. only keyword arguments can be in any order, but should be called
- at the end.
-
- Answer: only keyword arguments can be in any order, but should be called
- at the end.
-
-#. Given the following function, identify the keywords with default
- values.
- ::
-
- def seperator(char, count=40, show=False):
-
- if show:
- print char * count
-
- return char * count
-
- Answer: ``count``, ``show``
-
-#. Given the following function,
- ::
-
- def seperator(char, count=40, show=False):
-
- if show:
- print char * count
-
- return char * count
-
- What is the output of ``separator("+", 1, True)``.
-
- Answer: ``+`` is printed and returned.
-
-
-#. Given the following function,
- ::
-
- def seperator(char, count=40, show=False):
-
- if show:
- print char * count
-
- return char * count
-
- What is the output of ``separator("+", True, 1)``.
-
- Answer: ``+`` is printed and returned.
-
-#. Given the following function,
- ::
-
- def seperator(char, count=40, show=False):
-
- if show:
- print char * count
-
- return char * count
-
- What is the output of ``separator("+", show=True, 1)``.
-
- Answer: SyntaxError
-
-#. The following is a valid function definition. True or False? Why?
- ::
-
- def seperator(count=40, char, show=False):
-
- if show:
- print char * count
-
- return char * count
-
- Answer: False. All parameters with default arguments should be
- defined at the end.
-
-#. Which of the following cannot be used as default values for
- arguments?
-
- a. floats
- #. lists
- #. functions
- #. booleans
- #. None of the Above
-
- Answer: None of the above.
-
-
-Larger Questions
-----------------
-
-1.
-
-2.
--- a/advanced-features-functions/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-\textbf{Advanced features of functions}
-
-Arguments of functions can have default arguments.
-
-All arguments with default arguments are at the end of the definition.
-
-Functions can be called with keyword arguments. All the keyword
-arguments should be at the end of the argument list.
--- a/advanced-features-functions/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-.. Objectives
-.. ----------
-
-.. At the end of this tutorial, you will be able to
-
-.. 1. Assign default values to arguments, when defining functions
-.. 2. Define and call functions with keyword arguments.
-.. 3. Also, you will get a glimpse of the plethora of functions
-.. available, in Python standard library and the scientific computing
-.. libraries.
-
-
-.. Prerequisites
-.. -------------
-
-.. 1. getting started with ipython
-.. #. getting started with functions
-
-.. Author : Puneeth
- Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in>
- External Reviewer :
- Language Reviewer : Bhanukiran
- Checklist OK? : <put date stamp here, if OK> [2010-10-05]
-
-Script
-------
-
-{{{ Show the slide containing title }}}
-
-Welcome to the tutorial on advanced feature of functions.
-
-{{{ Show the outline slide }}}
-
-In this tutorial we shall be looking at specifying default arguments
-to functions when defining them and calling functions using keyword
-arguments. We shall also, look at some of the built-in functions
-available in the standard library of Python and the scientific
-computing libraries.
-
-{{{ switch to terminal }}}
-
-We have an ``ipython`` terminal open, which we shall be using through
-out this session.
-
-Let's use the ``round`` function as an example to understand what a
-default value of an argument means. Let's type the following
-expressions in the terminal.
-
-::
-
- round(2.484)
-
- round(2.484, 2)
-
-Both the first expression and the second are calls to the ``round``
-function, but the first calls it with only one argument and the second
-calls it with two arguments. By observing the output, we can guess
-that the first one is equivalent to call with the second argument
-being 0. 0 is the default value of the argument.
-
-.. #[[Anoop: It will be good if we show ``round??`` and tell them the
- optional argument ndigits, or it could be given as an
- exercise(solved) asking them to find the name of the argument in
- the function round]]
-
-{{{ show a slide with examples of functions showing default values }}}
-
-.. #[[Anoop: I think the slide is not there]]
-
-::
-
- s.strip() # strips on spaces.
- s.strip('@') # strips the string of '@' symbols.
-
- plot(x, y) # plots with x vs. y using default line style.
- plot(x, y, 'o') # plots x vs. y with circle markers.
-
- linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi
- linspace(0, 2*pi) # returns 50 points between 0 and 2pi
-
-.. #[punch: all above content goes on to a slide]
-
-{{{ switch back to ipython }}}
-
-Let's now define a simple function that uses default arguments. We
-define a simple function that prints a welcome message to a person,
-given a greeting and his/her name.
-
-::
-
- def welcome(greet, name="World"):
- print greet, name
-
-Let us first call the function with two arguments, one for ``greet``
-and other for ``name``.
-
-::
-
- welcome("Hi", "Guido")
-
-We get the expected welcome message, "Hi Guido".
-
-Now let us call the function with just one argument "Hello".
-::
-
- welcome("Hello")
-
-"Hello" is treated as the ``greet`` and we get "Hello World" as
-the output. "World" is the default value for the argument ``name``.
-
-Following is an (are) exercise(s) that you must do.
-
-{{{ switch to next slide, containing problem statement of
- question 1 }}}
-
-%%1%% Redefine the function ``welcome``, by interchanging it's
-arguments. Place the ``name`` argument with it's default value of
-"World" before the ``greet`` argument.
-
-Please, pause the video here. Do the exercise and then continue.
-
-{{{ switch to next slide, containing the solution to problem 1 }}}
-
-::
-
- def welcome(name="World", greet):
- print greet, name
-
-We get an error that reads ``SyntaxError: non-default argument follows
-default argument``. When defining a function all the argument with
-default values should come at the end.
-
-.. #[[Anoop: In the slide, "when defining a function all the default
- arguments must be defined at the end" has to be emphasized"]]
-
-Following is an exercise that you must do.
-
-{{{ switch to next slide, containing the problem statement of
- question 2 }}}
-
-%%2%% See the definition of linspace using ``?`` and observe how all
-the arguments with default values are towards the end.
-
-Please, pause the video here. Do the exercise and then continue.
-
-{{{ switch to next slide, containing solution to problem 2 }}}
-
-::
-
- linspace?
-
-Following is an exercise that you must do.
-
-{{{ switch to next slide, problem statement }}}
-
-%%3%% Redefine the function ``welcome`` with a default value of
-"Hello" to the ``greet`` argument. Then, call the function without any
-arguments.
-
-Please, pause the video here. Do the exercise and then continue.
-
-{{{ switch to next slide, solution }}}
-
-::
-
- def welcome(greet="Hello", name="World"):
- print greet, name
-
-
- welcome()
-
-
-Let us now learn what keyword arguments or named arguments are. We
-shall refer to them as keyword arguments, henceforth.
-
-{{{ show a slide with examples using keyword arguments. }}}
-
-.. #[[Anoop: slide is missing]]
-
-::
-
- legend(['sin(2y)'], loc = 'center')
-
- plot(y, sin(y), 'g', linewidth = 2)
-
- annotate('local max', xy = (1.5, 1))
-
- pie(science.values(), labels = science.keys())
-
-When you are calling functions in Python, you don't need to remember
-the order in which to pass the arguments. Instead, you can use the
-name of the argument to pass it a value. This slide shows a few
-function calls that use keyword arguments. ``loc``, ``linewidth``,
-``xy`` and ``labels`` are being called with keyword arguments.
-
-{{{ switch to ipython terminal }}}
-
-Let us try and understand this better using the ``welcome`` function
-that we have been using all along. Let us call it in different ways
-and observe the output to see how keyword arguments work.
-
-::
-
- welcome()
-
- welcome("Hello", "James")
-
- welcome("Hi", name="Guido")
-
-When no keyword is specified, the arguments are allotted based on
-their position. So, "Hi" is the value of the argument ``greet`` and
-name is passed the value "Guido".
-::
-
- welcome(name="Guido", greet="Hey! ")
-
-When keyword arguments are used, the arguments can be called in any
-order.
-
-::
-
- welcome(name="Guido", "Hey")
-
-This call returns an error that reads, ``non keyword arg after keyword
-arg``. Python expects all the keyword to be present towards the end.
-
-That brings us to the end of what we wanted to learn about ``keyword``
-arguments.
-
-{{{ switch to a slide showing variety of functions with uses }}}
-
-.. #[[Anoop: slide missing]]
-
-Before defining a function of your own, make sure that you check the
-standard library, for a similar function. Python is popularly called a
-"Batteries included" language, for the huge library that comes along
-with it.
-
-::
-
- Math functions - abs, sin, ....
-
-.. #[punch: Need to decide, exactly what to put here. Reviewer comments
-.. welcome.]
-
-{{{ switch to slide showing classes of functions in pylab, scipy }}}
-
-.. #[[Anoop: slide missing]]
-
-Apart from the standard library there are other libraries like ``pylab``,
-``scipy``, etc which have a huge collection of functions for scientific
-purposes.
-::
-
- pylab
- plot, bar, contour, boxplot, errorbar, log, polar, quiver, semilog
-
- scipy (modules)
- fftpack, stats, linalg, ndimage, signal, optimize, integrate
-
-{{{ Show summary slide }}}
-
-.. #[[Anoop: add range of functions available in python standard
- library]]
-
-That brings us to the end of this tutorial. In this tutorial we have
-learnt how to use functions with default values and keyword
-arguments. We also looked at the range of functions available in the
-Python standard library and the Scientific Computing related
-packages.
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-Thank you!
--- a/advanced-features-functions/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Advanced features of functions
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- - Assigning default values to arguments
- - Calling functions using Keyword arguments
- - functions in standard library
-* Question 1
- Redefine the function ~welcome~, by interchanging it's
- arguments. Place the ~name~ argument with it's default value of
- "World" before the ~greet~ argument.
-* Solution 1
- #+begin_src python
- def welcome(name="World", greet):
- print greet, name
- #+end_src
- We get an error that reads ~SyntaxError: non-default argument
- follows default argument~. When defining a function all the
- argument with default values should come at the end.
-
-* Question 2
- See the definition of linspace using ~?~ and observe how all the
- arguments with default values are towards the end.
-* Solution 2
- #+begin_src python
- linspace?
- #+end_src
-* Question 3
- Redefine the function ~welcome~ with a default value of
- "Hello" to the ~greet~ argument. Then, call the function without any
- arguments.
-* Solution 3
- #+begin_src python
- def welcome(greet="Hello", name="World"):
- print greet, name
-
- welcome()
- #+end_src
-* Summary
- You should now be able to --
- + define functions with default arguments
- + call functions using keyword arguments
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
--- a/advanced-features-functions/slides.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-% Created 2010-10-28 Thu 11:37
-\documentclass[presentation]{beamer}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{fixltx2e}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{t1enc}
-\usepackage{textcomp}
-\usepackage{marvosym}
-\usepackage{wasysym}
-\usepackage{latexsym}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\tolerance=1000
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-\providecommand{\alert}[1]{\textbf{#1}}
-
-\title{Advanced features of functions}
-\author{FOSSEE}
-\date{}
-
-\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-
-\begin{itemize}
-\item Assigning default values to arguments
-\item Calling functions using Keyword arguments
-\item functions in standard library
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-2}
-
- Redefine the function \texttt{welcome}, by interchanging it's
- arguments. Place the \texttt{name} argument with it's default value of
- ``World'' before the \texttt{greet} argument.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-3}
-
-\begin{verbatim}
-def welcome(name="World", greet):
- print greet, name
-\end{verbatim}
- We get an error that reads \texttt{SyntaxError: non-default argument follows default argument}. When defining a function all the
- argument with default values should come at the end.
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-4}
-
- See the definition of linspace using \texttt{?} and observe how all the
- arguments with default values are towards the end.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 2}
-\label{sec-5}
-
-\begin{verbatim}
-linspace?
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 3}
-\label{sec-6}
-
- Redefine the function \texttt{welcome} with a default value of
- ``Hello'' to the \texttt{greet} argument. Then, call the function without any
- arguments.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 3}
-\label{sec-7}
-
-\begin{verbatim}
-def welcome(greet="Hello", name="World"):
- print greet, name
-
-welcome()
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-8}
-
- You should now be able to --
-\begin{itemize}
-\item define functions with default arguments
-\item call functions using keyword arguments
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-9}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/advanced_features_of_functions/questions.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,109 @@
+Objective Questions
+-------------------
+
+.. A mininum of 8 questions here (along with answers)
+
+1. All arguments of a function cannot have default values. True or
+ False?
+
+ Answer: False
+
+#. When calling a function, the arguments
+
+ 1. should always be in the order in which they are defined.
+ #. can be in any order
+ #. only keyword arguments can be in any order, but should be called
+ at the beginning.
+ #. only keyword arguments can be in any order, but should be called
+ at the end.
+
+ Answer: only keyword arguments can be in any order, but should be called
+ at the end.
+
+#. Given the following function, identify the keywords with default
+ values.
+ ::
+
+ def seperator(char, count=40, show=False):
+
+ if show:
+ print char * count
+
+ return char * count
+
+ Answer: ``count``, ``show``
+
+#. Given the following function,
+ ::
+
+ def seperator(char, count=40, show=False):
+
+ if show:
+ print char * count
+
+ return char * count
+
+ What is the output of ``separator("+", 1, True)``.
+
+ Answer: ``+`` is printed and returned.
+
+
+#. Given the following function,
+ ::
+
+ def seperator(char, count=40, show=False):
+
+ if show:
+ print char * count
+
+ return char * count
+
+ What is the output of ``separator("+", True, 1)``.
+
+ Answer: ``+`` is printed and returned.
+
+#. Given the following function,
+ ::
+
+ def seperator(char, count=40, show=False):
+
+ if show:
+ print char * count
+
+ return char * count
+
+ What is the output of ``separator("+", show=True, 1)``.
+
+ Answer: SyntaxError
+
+#. The following is a valid function definition. True or False? Why?
+ ::
+
+ def seperator(count=40, char, show=False):
+
+ if show:
+ print char * count
+
+ return char * count
+
+ Answer: False. All parameters with default arguments should be
+ defined at the end.
+
+#. Which of the following cannot be used as default values for
+ arguments?
+
+ a. floats
+ #. lists
+ #. functions
+ #. booleans
+ #. None of the Above
+
+ Answer: None of the above.
+
+
+Larger Questions
+----------------
+
+1.
+
+2.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/advanced_features_of_functions/quickref.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,8 @@
+\textbf{Advanced features of functions}
+
+Arguments of functions can have default arguments.
+
+All arguments with default arguments are at the end of the definition.
+
+Functions can be called with keyword arguments. All the keyword
+arguments should be at the end of the argument list.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/advanced_features_of_functions/script.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,277 @@
+.. Objectives
+.. ----------
+
+.. At the end of this tutorial, you will be able to
+
+.. 1. Assign default values to arguments, when defining functions
+.. 2. Define and call functions with keyword arguments.
+.. 3. Also, you will get a glimpse of the plethora of functions
+.. available, in Python standard library and the scientific computing
+.. libraries.
+
+
+.. Prerequisites
+.. -------------
+
+.. 1. getting started with ipython
+.. #. getting started with functions
+
+.. Author : Puneeth
+ Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in>
+ External Reviewer :
+ Language Reviewer : Bhanukiran
+ Checklist OK? : <put date stamp here, if OK> [2010-10-05]
+
+Script
+------
+
+{{{ Show the slide containing title }}}
+
+Welcome to the tutorial on advanced feature of functions.
+
+{{{ Show the outline slide }}}
+
+In this tutorial we shall be looking at specifying default arguments
+to functions when defining them and calling functions using keyword
+arguments. We shall also, look at some of the built-in functions
+available in the standard library of Python and the scientific
+computing libraries.
+
+{{{ switch to terminal }}}
+
+We have an ``ipython`` terminal open, which we shall be using through
+out this session.
+
+Let's use the ``round`` function as an example to understand what a
+default value of an argument means. Let's type the following
+expressions in the terminal.
+
+::
+
+ round(2.484)
+
+ round(2.484, 2)
+
+Both the first expression and the second are calls to the ``round``
+function, but the first calls it with only one argument and the second
+calls it with two arguments. By observing the output, we can guess
+that the first one is equivalent to call with the second argument
+being 0. 0 is the default value of the argument.
+
+.. #[[Anoop: It will be good if we show ``round??`` and tell them the
+ optional argument ndigits, or it could be given as an
+ exercise(solved) asking them to find the name of the argument in
+ the function round]]
+
+{{{ show a slide with examples of functions showing default values }}}
+
+.. #[[Anoop: I think the slide is not there]]
+
+::
+
+ s.strip() # strips on spaces.
+ s.strip('@') # strips the string of '@' symbols.
+
+ plot(x, y) # plots with x vs. y using default line style.
+ plot(x, y, 'o') # plots x vs. y with circle markers.
+
+ linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi
+ linspace(0, 2*pi) # returns 50 points between 0 and 2pi
+
+.. #[punch: all above content goes on to a slide]
+
+{{{ switch back to ipython }}}
+
+Let's now define a simple function that uses default arguments. We
+define a simple function that prints a welcome message to a person,
+given a greeting and his/her name.
+
+::
+
+ def welcome(greet, name="World"):
+ print greet, name
+
+Let us first call the function with two arguments, one for ``greet``
+and other for ``name``.
+
+::
+
+ welcome("Hi", "Guido")
+
+We get the expected welcome message, "Hi Guido".
+
+Now let us call the function with just one argument "Hello".
+::
+
+ welcome("Hello")
+
+"Hello" is treated as the ``greet`` and we get "Hello World" as
+the output. "World" is the default value for the argument ``name``.
+
+Following is an (are) exercise(s) that you must do.
+
+{{{ switch to next slide, containing problem statement of
+ question 1 }}}
+
+%%1%% Redefine the function ``welcome``, by interchanging it's
+arguments. Place the ``name`` argument with it's default value of
+"World" before the ``greet`` argument.
+
+Please, pause the video here. Do the exercise and then continue.
+
+{{{ switch to next slide, containing the solution to problem 1 }}}
+
+::
+
+ def welcome(name="World", greet):
+ print greet, name
+
+We get an error that reads ``SyntaxError: non-default argument follows
+default argument``. When defining a function all the argument with
+default values should come at the end.
+
+.. #[[Anoop: In the slide, "when defining a function all the default
+ arguments must be defined at the end" has to be emphasized"]]
+
+Following is an exercise that you must do.
+
+{{{ switch to next slide, containing the problem statement of
+ question 2 }}}
+
+%%2%% See the definition of linspace using ``?`` and observe how all
+the arguments with default values are towards the end.
+
+Please, pause the video here. Do the exercise and then continue.
+
+{{{ switch to next slide, containing solution to problem 2 }}}
+
+::
+
+ linspace?
+
+Following is an exercise that you must do.
+
+{{{ switch to next slide, problem statement }}}
+
+%%3%% Redefine the function ``welcome`` with a default value of
+"Hello" to the ``greet`` argument. Then, call the function without any
+arguments.
+
+Please, pause the video here. Do the exercise and then continue.
+
+{{{ switch to next slide, solution }}}
+
+::
+
+ def welcome(greet="Hello", name="World"):
+ print greet, name
+
+
+ welcome()
+
+
+Let us now learn what keyword arguments or named arguments are. We
+shall refer to them as keyword arguments, henceforth.
+
+{{{ show a slide with examples using keyword arguments. }}}
+
+.. #[[Anoop: slide is missing]]
+
+::
+
+ legend(['sin(2y)'], loc = 'center')
+
+ plot(y, sin(y), 'g', linewidth = 2)
+
+ annotate('local max', xy = (1.5, 1))
+
+ pie(science.values(), labels = science.keys())
+
+When you are calling functions in Python, you don't need to remember
+the order in which to pass the arguments. Instead, you can use the
+name of the argument to pass it a value. This slide shows a few
+function calls that use keyword arguments. ``loc``, ``linewidth``,
+``xy`` and ``labels`` are being called with keyword arguments.
+
+{{{ switch to ipython terminal }}}
+
+Let us try and understand this better using the ``welcome`` function
+that we have been using all along. Let us call it in different ways
+and observe the output to see how keyword arguments work.
+
+::
+
+ welcome()
+
+ welcome("Hello", "James")
+
+ welcome("Hi", name="Guido")
+
+When no keyword is specified, the arguments are allotted based on
+their position. So, "Hi" is the value of the argument ``greet`` and
+name is passed the value "Guido".
+::
+
+ welcome(name="Guido", greet="Hey! ")
+
+When keyword arguments are used, the arguments can be called in any
+order.
+
+::
+
+ welcome(name="Guido", "Hey")
+
+This call returns an error that reads, ``non keyword arg after keyword
+arg``. Python expects all the keyword to be present towards the end.
+
+That brings us to the end of what we wanted to learn about ``keyword``
+arguments.
+
+{{{ switch to a slide showing variety of functions with uses }}}
+
+.. #[[Anoop: slide missing]]
+
+Before defining a function of your own, make sure that you check the
+standard library, for a similar function. Python is popularly called a
+"Batteries included" language, for the huge library that comes along
+with it.
+
+::
+
+ Math functions - abs, sin, ....
+
+.. #[punch: Need to decide, exactly what to put here. Reviewer comments
+.. welcome.]
+
+{{{ switch to slide showing classes of functions in pylab, scipy }}}
+
+.. #[[Anoop: slide missing]]
+
+Apart from the standard library there are other libraries like ``pylab``,
+``scipy``, etc which have a huge collection of functions for scientific
+purposes.
+::
+
+ pylab
+ plot, bar, contour, boxplot, errorbar, log, polar, quiver, semilog
+
+ scipy (modules)
+ fftpack, stats, linalg, ndimage, signal, optimize, integrate
+
+{{{ Show summary slide }}}
+
+.. #[[Anoop: add range of functions available in python standard
+ library]]
+
+That brings us to the end of this tutorial. In this tutorial we have
+learnt how to use functions with default values and keyword
+arguments. We also looked at the range of functions available in the
+Python standard library and the Scientific Computing related
+packages.
+
+{{{ Show the "sponsored by FOSSEE" slide }}}
+
+This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+
+Hope you have enjoyed and found it useful.
+Thank you!
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/advanced_features_of_functions/slides.org Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,86 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Advanced features of functions
+#+AUTHOR: FOSSEE
+#+EMAIL:
+#+DATE:
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+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
+ - Assigning default values to arguments
+ - Calling functions using Keyword arguments
+ - functions in standard library
+* Question 1
+ Redefine the function ~welcome~, by interchanging it's
+ arguments. Place the ~name~ argument with it's default value of
+ "World" before the ~greet~ argument.
+* Solution 1
+ #+begin_src python
+ def welcome(name="World", greet):
+ print greet, name
+ #+end_src
+ We get an error that reads ~SyntaxError: non-default argument
+ follows default argument~. When defining a function all the
+ argument with default values should come at the end.
+
+* Question 2
+ See the definition of linspace using ~?~ and observe how all the
+ arguments with default values are towards the end.
+* Solution 2
+ #+begin_src python
+ linspace?
+ #+end_src
+* Question 3
+ Redefine the function ~welcome~ with a default value of
+ "Hello" to the ~greet~ argument. Then, call the function without any
+ arguments.
+* Solution 3
+ #+begin_src python
+ def welcome(greet="Hello", name="World"):
+ print greet, name
+
+ welcome()
+ #+end_src
+* Summary
+ You should now be able to --
+ + define functions with default arguments
+ + call functions using keyword arguments
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/advanced_features_of_functions/slides.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,134 @@
+% Created 2010-10-28 Thu 11:37
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{t1enc}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Advanced features of functions}
+\author{FOSSEE}
+\date{}
+
+\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+
+\begin{itemize}
+\item Assigning default values to arguments
+\item Calling functions using Keyword arguments
+\item functions in standard library
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\label{sec-2}
+
+ Redefine the function \texttt{welcome}, by interchanging it's
+ arguments. Place the \texttt{name} argument with it's default value of
+ ``World'' before the \texttt{greet} argument.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-3}
+
+\begin{verbatim}
+def welcome(name="World", greet):
+ print greet, name
+\end{verbatim}
+ We get an error that reads \texttt{SyntaxError: non-default argument follows default argument}. When defining a function all the
+ argument with default values should come at the end.
+\end{frame}
+\begin{frame}
+\frametitle{Question 2}
+\label{sec-4}
+
+ See the definition of linspace using \texttt{?} and observe how all the
+ arguments with default values are towards the end.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 2}
+\label{sec-5}
+
+\begin{verbatim}
+linspace?
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 3}
+\label{sec-6}
+
+ Redefine the function \texttt{welcome} with a default value of
+ ``Hello'' to the \texttt{greet} argument. Then, call the function without any
+ arguments.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 3}
+\label{sec-7}
+
+\begin{verbatim}
+def welcome(greet="Hello", name="World"):
+ print greet, name
+
+welcome()
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-8}
+
+ You should now be able to --
+\begin{itemize}
+\item define functions with default arguments
+\item call functions using keyword arguments
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-9}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}
--- a/basic-data-type/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-Objective Questions
--------------------
-
-.. A mininum of 8 questions here (along with answers)
-
-.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
-.. question.]
-
-1. How large can an integer in Python be?
-
- Answer: Any Size.
-
-
-#. How do you define a complex number in Python?
-
- Using the following notation.
-
- [Real part] + [Imaginary part] j
- example ::
-
- Answer: c= 3.2 + 4.6j
-
-
-#. Look at the following piece of code ::
-
- In []: f or t
- Out[]:True
-
- What can you comment about the data type of f and t ?
-
-#. One major diffence between tuples and lists?
-
- Answer: Tuples are immutable while lists are not.
-
-
-
-
-#. Put the following string in a variable quotation.
- "God doesn't play dice" -Albert Einstein
-
- quotation='''"God doesn't play dice" -Albert Einstein'''
-
-#. Given a tuple ::
-
- tup=(7,4,2,1,3,6,5,8)
- tup[-2]
-
- 5
-
-.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
-.. question.]
-
-#. What is the syntax for checking containership in Python?::
-
- element in sequence
- 'l' in "Hello"
- True
-
-#. Split this string on whitespaces? ::
-
- string="Split this string on whitespaces?"
-
- string.split()
-
-#. What is the answer of 5/2 and 5.0/2 . If yes , why.
-
- Yes, There is a difference.
- Because one is integer division and other is float division.
-
-Larger Questions
-----------------
-
-.. A minimum of 2 questions here (along with answers)
-
-
-1. Look at the following sequence ::
-
- In []:t=true
- NameError: name 'true' is not defined
-
- What might be the reason for error here?
-
- In this scenario , it seems the programmer wanted to create a
- variable t with the boolean value True with a capital T. Since no
- variable by the name true(small t) is known to the interpreter it
- gives a NameError.
-
-
-
-#. Convert the string "I,learnt,python,through,spoken,tutorial"
- to "I,learnt through spoken tutorial"
-
-.. #[Puneeth: comparison has not been taught, has it? does this depend
-.. on any other LO?]
--- a/basic-data-type/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-\documentclass{article}
-\begin{Document}
-\begin{center}
-\textbf{Basic DataType Quick Reference}\\
-\end{center}
-Declaring an Integer:\\
-{\ex \lstinline| b=9999999999999999999 |}
-
-Declaring a float:\\
-{\ex \lstinline| p=3.141592 |}
-
-Declaring a Complex number:\\
-{\ex \lstinline| c = 3.2+4.6j |}
-
-Modulo Operator:\\
-{\ex \lstinline| 87 % 6 |}
-
-Exponent Operator:\\
-{\ex \lstinline| 7**8 |}
-
-Declaring a list:\\
-{\ex \lstinline| var_list = [1, 1.2, [1,2]] |}
-
-Declaring a string:\\
-{\ex \lstinline| k='Single quote' |}
-{\ex \lstinline| l="Double quote contain's single quote" |}
-{\ex \lstinline| m='''"Contain's both"''' |}
-
-Declaring a tuple:\\
-{\ex \lstinline| var_tup = (1,2,3,4) |}
-
-
-Accessing Lists, string and tuples:\\
-{\ex \lstinline| seq[-1] |}
-
-Interconversion of number datatype:\\
-{\ex \lstinline| float(2.3+4.2j) |}
-
-
-Interconversion of sequences:\\
-{\ex \lstinline| tup=tuple([1,2,3,4,5]) |}
-
-Spliting string into lists:\\
-{\ex \lstinline| ''split this sting''.split() |}
-
-Join lists to create strings:\\
-{\ex \lstinline| ','.join['List','joined','on','commas'] |}
-
-\end{Document}
--- a/basic-data-type/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,553 +0,0 @@
-.. Objectives
-.. ----------
-
-.. At the end of this tutorial, you should know --
-
-.. 1. Learn about Python Data Structures and Operators.(Remembering)
-.. #.Use them to do basic operations.(Applying)
-
-.. Prerequisites
-.. -------------
-
-.. None
-
-.. Author : Amit Sethi
- Internal Reviewer :
- External Reviewer :
- Checklist OK? : <put date stamp here, if OK> [2010-10-05]
-
-Hello friends and welcome to the tutorial on Basic Data types and operators
-in Python.
-
-{{{ Show the slide containing title }}}
-
-{{{ Show the slide containing the outline slide }}}
-
-In this tutorial, we shall look at
-
-* Datatypes in Python
- * Numbers
- * Boolean
- * Sequence
-* Operators in Python
- * Arithmetic Operators
- * Boolean Operators
-
-* Python Sequence Data types
- * list
- * string
- * tuple
-
-First we will explore python data structures in the domain of numbers.
-There are three built-in data types in python to represent numbers.
-
-{{{ A slide to make a memory note of the different datatypes }}}
-
-These are:
-
- * int
- * float
- * complex
-
-Lets first talk about int. ::
-
- a = 13
- a
-
-
-Now, we have our first int variable a.
-
-
-If we now see ::
-
- type(a)
- <type 'int'>
-
-This means that a is a type of int. There are lot of functions associated
-with the int datatype, to manipulate it in different ways. These can be
-explored by doing, ::
-
- a.<Tab>
-
-*int* datatype can hold integers of any size lets see this by an example.
-::
-
- b = 99999999999999999999
- b
-
-As you can see even when we put a value of 9 repeated 20 times python did
-not complain. This is because python's int data-type can hold integers of any
-size.
-
-Let us now look at the float data-type.
-
-Decimal numbers in python are represented by the float data-type ::
-
- p = 3.141592
- p
-
-If you notice the value of output of ``p`` isn't exactly equal to ``p``.
-This is because computer saves floating point values in a specific format.
-There is always an approximation. This is why we should never rely on
-equality of floating point numbers in a program.
-
-The last data type in the list is complex number ::
-
- c = 3.2+4.6j
-
-as simple as that so essentialy its just a combination of two floats the
-imaginary part being defined by j notation instead of i. Complex numbers
-have a lot of functions specific to them. Let us look at these ::
-
- c.<Tab>
-
-Lets try some of them ::
-
- c.real
- c.imag
-
-c.real gives the real part of the number and c.imag the imaginary.
-
-We can get the absolute value using the function ::
-
- abs(c)
-
-
-Following is are exercises that you must do.
-
-%% %% Find the absolute value of 3+4j
-::
-
- abs(3+4j)
-
-%% %% What is the datatype of number 999999999999999999? Is it
-not int?
-::
-
- Long
- Big integers are internally stored in python
- as Long datatype.
-
-Please, pause the video here. Do the exercises and then continue.
-
-
-{{ Slide for showing Boolean datatypes }}
-
-Python also has Boolean as a built-in type.
-
-Try it out just type ::
-
- t = True
-
-note that T in true is capitalized.
-
-You can apply different Boolean operations on t now for example ::
-
- f = not t
- f
- f or t
- f and t
-
-
-The results are self explanatory.
-
-What if you want to apply one operator before another.
-
-Well you can use parenthesis for precedence.
-
-Lets write some piece of code to check this out.::
-
- a=False
- b=True
- c=True
-
-
-To check how precedence changes with parenthesis, we will try two
-expressions and their evaluation.
-
-one ::
-
- (a and b) or c
-
-This expression gives the value True
-
-where as the expression ::
-
- a and (b or c)
-
-gives the value False.
-
-
-Let's now look at some operators available in Python to manipulate
-these data types.
-
-Python uses '+' for addition ::
-
- 23 + 74
-
-'-' for subtraction ::
-
- 23 - 56
-
-'*' for multiplication ::
-
- 45*76
-
-'/' for division ::
-
- 384/16
- 8/3
- 8.0/3
-
-When we did 8/3 the first case results in am integer
-output as both the operands are integer however when
-8.0/3 is used the answer is float as one of the operands is
-float.
-
-
-'%' for modulo operation ::
-
- 87 % 6
-
-and two stars for a exponent. ::
-
- 7**8
-
-
-In case one wishes to use the current value of variable in which the result
-is stored in the expression one can do that by putting the operator before
-`equal to`. ::
-
- a=73
- a*=34
-
-is same as ::
-
- a=a*34
-
-and ::
-
- a/=23
-
-is same as ::
-
- a=a/23
-
-Following is are exercises that you must do.
-
-%% %% Using python find sqaure root of 3?
-
-%% %% Is 3**1/2 and 3**0.5 same
-
-Please, pause the video here. Do the exercises and then continue.
-
-::
-
- 3**0.5
-
-::
- No,One gives an int answer and the other float
-
-
-Lets now discuss sequence data types in Python. Sequence data types
-are those in which elements are kept in a sequential order and all the
-elements are accessed using index numbers.
-
-{{{ slide introducing sequence datatype }}}
-
-The sequence datatypes in Python are ::
-
- * list
- * string
- * tuple
-
-The list type is a container that holds a number of other objects, in the
-given order.
-
-We create our first list by typing ::
-
- num_list = [1, 2, 3, 4]
- num_list
-
-
-Items enclosed in square brackets separated by comma constitutes a list.
-
-Lists can store data of any type in them.
-
-We can have a list something like ::
-
- var_list = [1, 1.2, [1,2]]
- var_list
-
-Lets look at another sequence data type, strings
-
-type ::
-
- greeting_string="hello"
-
-
-greeting_string is now a string variable with the value "hello"
-
-{{{ All the different types of strings shown }}}
-
-Python strings can actually be defined in three different ways ::
-
- k='Single quote'
- l="Let's see how to include a single quote"
- m='''"Let's see how to include both"'''
-
-As you can see, single quotes are used as delimiters usually.
-
-When a string contains a single quote, double quotes are used as
-delimiters. When a string quote contains both single and double quotes,
-triple quotes are used as delimiters.
-
-The last in the list of sequence data types is tuple.
-
-To create a tuple we use normal brackets '(' unlike '[' for lists.::
-
- num_tuple = (1, 2, 3, 4, 5, 6, 7, 8)
-
-Because of their sequential property there are certain functions and
-operations we can apply to all of them.
-
-
-
-The first one is accessing.
-
-They can be accessed using index numbers ::
-
- num_list[2]
- num_list[-1]
- greeting_string[1]
- greeting_string[3]
- greeting_string[-2]
- num_tuple[2]
- num_tuple[-3]
-
-
-Indexing starts from 0 from left to right and from -1 when accessing lists
-in reverse. Thus num_list[2] refers to the third element 3. and greetings
-[-2] is the second element from the end , that is 'l'.
-
-
-
-Addition gives a new sequence containing both sequences ::
-
- num_list+var_list
- a_string="another string"
- greeting_string+a_string
- t2=(3,4,6,7)
- num_tuple+t2
-
-len function gives the length ::
-
- len(num_list)
- len(greeting_string)
- len(num_tuple)
-
-Prints the length the variable.
-
-We can check the containership of an element using the 'in' keyword ::
-
- 3 in num_list
- 'H' in greeting_string
- 2 in num_tuple
-
-We see that it gives True and False accordingly.
-
-Find maximum using max function and minimum using min::
-
- max(num_tuple)
- min(greeting_string)
-
-Get a sorted list ::
-
- sorted(num_list)
-
-
-As a consequence of their order, we can access a group of elements in a
-sequence, together. This is called slicing and striding.
-
-First lets discuss Slicing,
-
-Given a list ::
-
- j=[1,2,3,4,5,6]
-
-Lets say we want elements starting from 2 and ending in 5.
-
-For this we can do ::
-
- j[1:4]
-
-The syntax for slicing is, sequence variable name square bracket first
-element index, colon, second element index. The last element however is not
-included in the resultant list::
-
-
- j[:4]
-
-If first element is left blank default is from beginning and if last
-element is left blank it means till the end.
-
-::
-
- j[1:]
-
- j[:]
-
-This effectively is the whole list.
-
-Striding is similar to slicing except that the step size here is not one.
-
-Lets see by example ::
-
- new_num_list=[1,2,3,4,5,6,7,8,9,10]
- new_num_list[1:8:2]
- [2, 4, 6, 8]
-
-The colon two added in the end signifies all the alternate elements. This
-is why we call this concept striding because we move through the list with
-a particular stride or step. The step in this example being 2.
-
-We have talked about many similar features of lists, strings and tuples.
-But there are many important features in lists that differ from strings and
-tuples. Lets see this by example.::
-
- new_num_list[1]=9
- greeting_string[1]='k'
-
-{{{ slide to show the error }}}
-
-
-
-As you can see while the first command executes with out a problem there is
-an error on the second one.
-
-Now lets try ::
-
- new_tuple[1]=5
-
-Its the same error. This is because strings and tuples share the property
-of being immutable. We cannot change the value at a particular index just
-by assigning a new value at that position.
-
-
-We have looked at different types but we need to convert one data type into
-another. Well lets one by one go through methods by which we can convert
-one data type to other:
-
-We can convert all the number data types to one another ::
-
- i=34
- d=float(i)
- d
-
-Python has built in functions int, float and complex to convert one number
-type data structure to another.
-
-::
-
- dec=2.34
- dec_con=int(dec)
- dec_con
-
-
-As you can see the decimal part of the number is simply stripped to get the
-integer.::
-
- com=2.3+4.2j
- float(com)
- com
-
-In case of complex number to floating point only the real value of complex
-number is taken.
-
-Similarly we can convert list to tuple and tuple to list ::
-
- lst=[3,4,5,6]
- tup=tuple(lst)
- tupl=(3,23,4,56)
- lst=list(tuple)
-
-However converting a string to a list and a list to a string is an
-interesting problem. Let's say we have a string ::
-
- In: somestring="Is there a way to split on these spaces."
- In: somestring.split()
-
-
-This produces a list with the string split at whitespace. Similarly we can
-split on some other character.
-
-::
-
- In: otherstring="Tim,Amy,Stewy,Boss"
-
-How do we split on comma , simply pass it as argument ::
-
- In: otherstring.split(',')
-
-join function does the opposite. Joins a list to make a string.::
-
- ','.join['List','joined','on','commas']
-
-Thus we get a list joined on commas. Similarly we can do spaces.::
-
- ' '.join['Now','on','spaces']
-
-Note that the list has to be a list of strings to apply join operation.
-
-With this we come to the end of this tutorial .
-
-Following is an (are) exercise(s) that you must do.
-
-
-
-%% %% Check if 3 is an element of the list [1,7,5,3,4]. In case
-it is change it to 21.
-::
- l=[1,7,5,3,4]
- 3 in l
- l[3]=21
- l
-
-%% %% Convert the string "Elizabeth is queen of england" to
-"Elizabeth is queen"
-::
-
- s="Elizabeth is queen of england"
- stemp=s.split()
- ' '.join(stemp[:3])
-
-Please, pause the video here. Do the exercise(s) and then continue.
-
-
-This brings us to the end of the tutorial. In this tutorial we have
-discussed
-
-1. Number Datatypes , integer,float and complex
-2. Boolean and datatype and operators
-3. Sequence data types ,List,String and Tuple
-4. Accesing sequence
-5. Slicing sequences
-6. Finding length , sorting and reversing operations on sequences.
-7. Immutability.
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-
-Thank You.
-
-
-..
- Local Variables:
- mode: rst
- indent-tabs-mode: nil
- sentence-end-double-space: nil
- fill-column: 75
- End:
--- a/basic-data-type/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Plotting Data
-#+AUTHOR: FOSSEE
-#+DATE: 2010-09-14 Tue
-#+EMAIL: info@fossee.in
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+OPTIONS: H:1 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
-#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
-
-* Outline
-** Datatypes in Python
-*** Numbers
-*** Boolean
-*** Sequence
-** Operators in Python
-*** Arithmetic Operators
-*** Boolean Operators
-** Python Sequence Datatypes
-*** list
-*** string
-*** tuple
-
-* Numbers
- - int
- - float
- - complex
-* Question 1
- - Find the absolute value of 3+4j
-* Solution 1
- #+begin_src python
- abs(3+4j)
- #+end_src python
-* Question 2
- - What is the datatype of number 999999999999999999? Is it
-not int?
-
-* Solution 2
- - Long
- - Large integers numbers are internally stored in python as Long
- datatype.
-
-
-* Boolean
- #+begin_src python
- In []: t=True
- In []: f=False
- #+end_src
-
-* Question 3
- - Using python find sqaure root of 3?
-
-* Solution 3
-
- - 3**0.5
-
-* Question 4
- - Is 3**1/2 and 3**0.5 same
-* Solution 4
- - No,One gives an int answer and the other float
-
-* Sequence Data types
-** Properties
- - Data in Sequence
- - Accessed using Index
-** Type
- - list
- - String
- - Tuple
-
-* All are Strings
- #+begin_src python
- k = 'Single quote'
- l = "Double quote contain's single quote"
- m = '''"Contain's both"'''
-
- #+end_src
-* Immutabilty Error
- #+begin_src python
- In []: greeting_string[1]='k'
- -------------------------------------------------------
- TypeError Traceback (most recent call last)
-
- /home/fossee/<ipython console> in <module>()
-
- TypeError: 'str' object does not support item assignment
- #+end_src
-
-* Question 5
- Check if 3 is an element of the list [1,7,5,3,4]. In case it is
-change it to 21.
-
-* Solution 5
- #+begin_src python
- l=[1,7,5,3,4]
- 3 in l
- l[3]=21
- l
- #+end_src
-* Question 6
- Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is
-queen"~
-
-* Solution 6
- #+begin_src python
- s = "Elizabeth is queen of england"
- stemp = s.split()
- ' '.join(stemp[:3])
- #+end_src
-* Summary
- - Number Datatypes -- integer,float and complex
- - Boolean and datatype and operators
- - Sequence data types -- List, String and Tuple
- - Accesing sequence
- - Slicing sequences
- - Finding length, sorting and reversing operations on sequences
- - Immutability
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
-
-
-
--- a/basic-data-type/slides.org.orig Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Plotting Data
-#+AUTHOR: FOSSEE
-#+DATE: 2010-09-14 Tue
-#+EMAIL: info@fossee.in
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+OPTIONS: H:1 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
-#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
-
-* Outline
-** Datatypes in Python
-*** Numbers
-*** Boolean
-*** Sequence
-** Operators in Python
-*** Arithmetic Operators
-*** Boolean Operators
-** Python Sequence Datatypes
-*** list
-*** string
-*** tuple
-
-* Numbers
- - int
- - float
- - complex
-* Question 1
- - Find the absolute value of 3+4j
-* Solution 1
- #+begin_src python
- abs(3+4j)
- #+end_src python
-* Question 2
- - What is the datatype of number 999999999999999999? Is it
-not int?
-
-* Solution 2
- - Long
- - Large integers numbers are internally stored in python as Long
- datatype.
-
-
-* Boolean
- #+begin_src python
- In []: t=True
- In []: f=False
- #+end_src
-
-* Question 3
- - Using python find sqaure root of 3?
-
-* Solution 3
-
- - 3**0.5
-
-* Question 4
- - Is 3**1/2 and 3**0.5 same
-* Solution 4
- - No,One gives an int answer and the other float
-
-* Sequence Data types
-** Properties
- - Data in Sequence
- - Accessed using Index
-** Type
- - list
- - String
- - Tuple
-
-* All are Strings
- #+begin_src python
- k = 'Single quote'
- l = "Double quote contain's single quote"
- m = '''"Contain's both"'''
-
- #+end_src
-* Immutabilty Error
- #+begin_src python
- In []: greeting_string[1]='k'
- -------------------------------------------------------
- TypeError Traceback (most recent call last)
-
- /home/fossee/<ipython console> in <module>()
-
- TypeError: 'str' object does not support item assignment
- #+end_src
-
-* Question 5
- Check if 3 is an element of the list [1,7,5,3,4]. In case it is
-change it to 21.
-
-* Solution 5
- #+begin_src python
- l=[1,7,5,3,4]
- 3 in l
- l[3]=21
- l
- #+end_src
-* Question 6
- Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is
-queen"~
-
-* Solution 6
- #+begin_src python
- s = "Elizabeth is queen of england"
- stemp = s.split()
- ' '.join(stemp[:3])
- #+end_src
-* Summary
- - Number Datatypes -- integer,float and complex
- - Boolean and datatype and operators
- - Sequence data types -- List, String and Tuple
- - Accesing sequence
- - Slicing sequences
- - Finding length, sorting and reversing operations on sequences
- - Immutability
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
-
-
-
--- a/basic-data-type/slides.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,286 +0,0 @@
-% Created 2010-11-09 Tue 15:26
-\documentclass[presentation]{beamer}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{fixltx2e}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{t1enc}
-\usepackage{textcomp}
-\usepackage{marvosym}
-\usepackage{wasysym}
-\usepackage{latexsym}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\tolerance=1000
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-\providecommand{\alert}[1]{\textbf{#1}}
-
-\title{Plotting Data }
-\author{FOSSEE}
-\date{2010-09-14 Tue}
-
-\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-\begin{itemize}
-
-\item Datatypes in Python
-\label{sec-1_1}%
-\begin{itemize}
-
-\item Numbers\\
-\label{sec-1_1_1}%
-\item Boolean\\
-\label{sec-1_1_2}%
-\item Sequence\\
-\label{sec-1_1_3}%
-\end{itemize} % ends low level
-
-\item Operators in Python
-\label{sec-1_2}%
-\begin{itemize}
-
-\item Arithmetic Operators\\
-\label{sec-1_2_1}%
-\item Boolean Operators\\
-\label{sec-1_2_2}%
-\end{itemize} % ends low level
-
-\item Python Sequence Datatypes
-\label{sec-1_3}%
-\begin{itemize}
-
-\item list\\
-\label{sec-1_3_1}%
-\item string\\
-\label{sec-1_3_2}%
-\item tuple\\
-\label{sec-1_3_3}%
-\end{itemize} % ends low level
-\end{itemize} % ends low level
-\end{frame}
-\begin{frame}
-\frametitle{Numbers}
-\label{sec-2}
-
-\begin{itemize}
-\item int
-\item float
-\item complex
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-3}
-
-\begin{itemize}
-\item Find the absolute value of 3+4j
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-4}
-
-\begin{verbatim}
-abs(3+4j)
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-5}
-
-\begin{itemize}
-\item What is the datatype of number 999999999999999999? Is it
-\end{itemize}
-
-not int?
-\end{frame}
-\begin{frame}
-\frametitle{Solution 2}
-\label{sec-6}
-
-\begin{itemize}
-\item Long
-\item Large integers numbers are internally stored in python as Long
- datatype.
-\end{itemize}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Boolean}
-\label{sec-7}
-
-\begin{verbatim}
-In []: t=True
-In []: f=False
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 3}
-\label{sec-8}
-
-\begin{itemize}
-\item Using python find sqaure root of 3?
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Solution 3}
-\label{sec-9}
-
-
-\begin{itemize}
-\item 3**0.5
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Question 4}
-\label{sec-10}
-
-\begin{itemize}
-\item Is 3**1/2 and 3**0.5 same
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Solution 4}
-\label{sec-11}
-
-\begin{itemize}
-\item No,One gives an int answer and the other float
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Sequence Data types}
-\label{sec-12}
-\begin{itemize}
-
-\item Properties
-\label{sec-12_1}%
-\begin{itemize}
-\item Data in Sequence
-\item Accessed using Index
-\end{itemize}
-
-
-\item Type
-\label{sec-12_2}%
-\begin{itemize}
-\item list
-\item String
-\item Tuple
-\end{itemize}
-
-
-\end{itemize} % ends low level
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{All are Strings}
-\label{sec-13}
-
-\begin{verbatim}
-k = 'Single quote'
-l = "Double quote contain's single quote"
-m = '''"Contain's both"'''
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Immutabilty Error}
-\label{sec-14}
-
-\begin{verbatim}
-In []: greeting_string[1]='k'
--------------------------------------------------------
-TypeError Traceback (most recent call last)
-
-/home/fossee/<ipython console> in <module>()
-
-TypeError: 'str' object does not support item assignment
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 5}
-\label{sec-15}
-
- Check if 3 is an element of the list [1,7,5,3,4]. In case it is
-change it to 21.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 5}
-\label{sec-16}
-
-\begin{verbatim}
-l=[1,7,5,3,4]
-3 in l
-l[3]=21
-l
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 6}
-\label{sec-17}
-
- Convert the string \~{}''Elizabeth is queen of england''\~{} to \~{}''Elizabeth is
-queen''\~{}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 6}
-\label{sec-18}
-
-\begin{verbatim}
-s = "Elizabeth is queen of england"
-stemp = s.split()
-' '.join(stemp[:3])
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-19}
-
-\begin{itemize}
-\item Number Datatypes -- integer,float and complex
-\item Boolean and datatype and operators
-\item Sequence data types -- List, String and Tuple
-\item Accesing sequence
-\item Slicing sequences
-\item Finding length, sorting and reversing operations on sequences
-\item Immutability
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-20}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/questions.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,94 @@
+Objective Questions
+-------------------
+
+.. A mininum of 8 questions here (along with answers)
+
+.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
+.. question.]
+
+1. How large can an integer in Python be?
+
+ Answer: Any Size.
+
+
+#. How do you define a complex number in Python?
+
+ Using the following notation.
+
+ [Real part] + [Imaginary part] j
+ example ::
+
+ Answer: c= 3.2 + 4.6j
+
+
+#. Look at the following piece of code ::
+
+ In []: f or t
+ Out[]:True
+
+ What can you comment about the data type of f and t ?
+
+#. One major diffence between tuples and lists?
+
+ Answer: Tuples are immutable while lists are not.
+
+
+
+
+#. Put the following string in a variable quotation.
+ "God doesn't play dice" -Albert Einstein
+
+ quotation='''"God doesn't play dice" -Albert Einstein'''
+
+#. Given a tuple ::
+
+ tup=(7,4,2,1,3,6,5,8)
+ tup[-2]
+
+ 5
+
+.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
+.. question.]
+
+#. What is the syntax for checking containership in Python?::
+
+ element in sequence
+ 'l' in "Hello"
+ True
+
+#. Split this string on whitespaces? ::
+
+ string="Split this string on whitespaces?"
+
+ string.split()
+
+#. What is the answer of 5/2 and 5.0/2 . If yes , why.
+
+ Yes, There is a difference.
+ Because one is integer division and other is float division.
+
+Larger Questions
+----------------
+
+.. A minimum of 2 questions here (along with answers)
+
+
+1. Look at the following sequence ::
+
+ In []:t=true
+ NameError: name 'true' is not defined
+
+ What might be the reason for error here?
+
+ In this scenario , it seems the programmer wanted to create a
+ variable t with the boolean value True with a capital T. Since no
+ variable by the name true(small t) is known to the interpreter it
+ gives a NameError.
+
+
+
+#. Convert the string "I,learnt,python,through,spoken,tutorial"
+ to "I,learnt through spoken tutorial"
+
+.. #[Puneeth: comparison has not been taught, has it? does this depend
+.. on any other LO?]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/quickref.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,49 @@
+\documentclass{article}
+\begin{Document}
+\begin{center}
+\textbf{Basic DataType Quick Reference}\\
+\end{center}
+Declaring an Integer:\\
+{\ex \lstinline| b=9999999999999999999 |}
+
+Declaring a float:\\
+{\ex \lstinline| p=3.141592 |}
+
+Declaring a Complex number:\\
+{\ex \lstinline| c = 3.2+4.6j |}
+
+Modulo Operator:\\
+{\ex \lstinline| 87 % 6 |}
+
+Exponent Operator:\\
+{\ex \lstinline| 7**8 |}
+
+Declaring a list:\\
+{\ex \lstinline| var_list = [1, 1.2, [1,2]] |}
+
+Declaring a string:\\
+{\ex \lstinline| k='Single quote' |}
+{\ex \lstinline| l="Double quote contain's single quote" |}
+{\ex \lstinline| m='''"Contain's both"''' |}
+
+Declaring a tuple:\\
+{\ex \lstinline| var_tup = (1,2,3,4) |}
+
+
+Accessing Lists, string and tuples:\\
+{\ex \lstinline| seq[-1] |}
+
+Interconversion of number datatype:\\
+{\ex \lstinline| float(2.3+4.2j) |}
+
+
+Interconversion of sequences:\\
+{\ex \lstinline| tup=tuple([1,2,3,4,5]) |}
+
+Spliting string into lists:\\
+{\ex \lstinline| ''split this sting''.split() |}
+
+Join lists to create strings:\\
+{\ex \lstinline| ','.join['List','joined','on','commas'] |}
+
+\end{Document}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/script.rst Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,553 @@
+.. Objectives
+.. ----------
+
+.. At the end of this tutorial, you should know --
+
+.. 1. Learn about Python Data Structures and Operators.(Remembering)
+.. #.Use them to do basic operations.(Applying)
+
+.. Prerequisites
+.. -------------
+
+.. None
+
+.. Author : Amit Sethi
+ Internal Reviewer :
+ External Reviewer :
+ Checklist OK? : <put date stamp here, if OK> [2010-10-05]
+
+Hello friends and welcome to the tutorial on Basic Data types and operators
+in Python.
+
+{{{ Show the slide containing title }}}
+
+{{{ Show the slide containing the outline slide }}}
+
+In this tutorial, we shall look at
+
+* Datatypes in Python
+ * Numbers
+ * Boolean
+ * Sequence
+* Operators in Python
+ * Arithmetic Operators
+ * Boolean Operators
+
+* Python Sequence Data types
+ * list
+ * string
+ * tuple
+
+First we will explore python data structures in the domain of numbers.
+There are three built-in data types in python to represent numbers.
+
+{{{ A slide to make a memory note of the different datatypes }}}
+
+These are:
+
+ * int
+ * float
+ * complex
+
+Lets first talk about int. ::
+
+ a = 13
+ a
+
+
+Now, we have our first int variable a.
+
+
+If we now see ::
+
+ type(a)
+ <type 'int'>
+
+This means that a is a type of int. There are lot of functions associated
+with the int datatype, to manipulate it in different ways. These can be
+explored by doing, ::
+
+ a.<Tab>
+
+*int* datatype can hold integers of any size lets see this by an example.
+::
+
+ b = 99999999999999999999
+ b
+
+As you can see even when we put a value of 9 repeated 20 times python did
+not complain. This is because python's int data-type can hold integers of any
+size.
+
+Let us now look at the float data-type.
+
+Decimal numbers in python are represented by the float data-type ::
+
+ p = 3.141592
+ p
+
+If you notice the value of output of ``p`` isn't exactly equal to ``p``.
+This is because computer saves floating point values in a specific format.
+There is always an approximation. This is why we should never rely on
+equality of floating point numbers in a program.
+
+The last data type in the list is complex number ::
+
+ c = 3.2+4.6j
+
+as simple as that so essentialy its just a combination of two floats the
+imaginary part being defined by j notation instead of i. Complex numbers
+have a lot of functions specific to them. Let us look at these ::
+
+ c.<Tab>
+
+Lets try some of them ::
+
+ c.real
+ c.imag
+
+c.real gives the real part of the number and c.imag the imaginary.
+
+We can get the absolute value using the function ::
+
+ abs(c)
+
+
+Following is are exercises that you must do.
+
+%% %% Find the absolute value of 3+4j
+::
+
+ abs(3+4j)
+
+%% %% What is the datatype of number 999999999999999999? Is it
+not int?
+::
+
+ Long
+ Big integers are internally stored in python
+ as Long datatype.
+
+Please, pause the video here. Do the exercises and then continue.
+
+
+{{ Slide for showing Boolean datatypes }}
+
+Python also has Boolean as a built-in type.
+
+Try it out just type ::
+
+ t = True
+
+note that T in true is capitalized.
+
+You can apply different Boolean operations on t now for example ::
+
+ f = not t
+ f
+ f or t
+ f and t
+
+
+The results are self explanatory.
+
+What if you want to apply one operator before another.
+
+Well you can use parenthesis for precedence.
+
+Lets write some piece of code to check this out.::
+
+ a=False
+ b=True
+ c=True
+
+
+To check how precedence changes with parenthesis, we will try two
+expressions and their evaluation.
+
+one ::
+
+ (a and b) or c
+
+This expression gives the value True
+
+where as the expression ::
+
+ a and (b or c)
+
+gives the value False.
+
+
+Let's now look at some operators available in Python to manipulate
+these data types.
+
+Python uses '+' for addition ::
+
+ 23 + 74
+
+'-' for subtraction ::
+
+ 23 - 56
+
+'*' for multiplication ::
+
+ 45*76
+
+'/' for division ::
+
+ 384/16
+ 8/3
+ 8.0/3
+
+When we did 8/3 the first case results in am integer
+output as both the operands are integer however when
+8.0/3 is used the answer is float as one of the operands is
+float.
+
+
+'%' for modulo operation ::
+
+ 87 % 6
+
+and two stars for a exponent. ::
+
+ 7**8
+
+
+In case one wishes to use the current value of variable in which the result
+is stored in the expression one can do that by putting the operator before
+`equal to`. ::
+
+ a=73
+ a*=34
+
+is same as ::
+
+ a=a*34
+
+and ::
+
+ a/=23
+
+is same as ::
+
+ a=a/23
+
+Following is are exercises that you must do.
+
+%% %% Using python find sqaure root of 3?
+
+%% %% Is 3**1/2 and 3**0.5 same
+
+Please, pause the video here. Do the exercises and then continue.
+
+::
+
+ 3**0.5
+
+::
+ No,One gives an int answer and the other float
+
+
+Lets now discuss sequence data types in Python. Sequence data types
+are those in which elements are kept in a sequential order and all the
+elements are accessed using index numbers.
+
+{{{ slide introducing sequence datatype }}}
+
+The sequence datatypes in Python are ::
+
+ * list
+ * string
+ * tuple
+
+The list type is a container that holds a number of other objects, in the
+given order.
+
+We create our first list by typing ::
+
+ num_list = [1, 2, 3, 4]
+ num_list
+
+
+Items enclosed in square brackets separated by comma constitutes a list.
+
+Lists can store data of any type in them.
+
+We can have a list something like ::
+
+ var_list = [1, 1.2, [1,2]]
+ var_list
+
+Lets look at another sequence data type, strings
+
+type ::
+
+ greeting_string="hello"
+
+
+greeting_string is now a string variable with the value "hello"
+
+{{{ All the different types of strings shown }}}
+
+Python strings can actually be defined in three different ways ::
+
+ k='Single quote'
+ l="Let's see how to include a single quote"
+ m='''"Let's see how to include both"'''
+
+As you can see, single quotes are used as delimiters usually.
+
+When a string contains a single quote, double quotes are used as
+delimiters. When a string quote contains both single and double quotes,
+triple quotes are used as delimiters.
+
+The last in the list of sequence data types is tuple.
+
+To create a tuple we use normal brackets '(' unlike '[' for lists.::
+
+ num_tuple = (1, 2, 3, 4, 5, 6, 7, 8)
+
+Because of their sequential property there are certain functions and
+operations we can apply to all of them.
+
+
+
+The first one is accessing.
+
+They can be accessed using index numbers ::
+
+ num_list[2]
+ num_list[-1]
+ greeting_string[1]
+ greeting_string[3]
+ greeting_string[-2]
+ num_tuple[2]
+ num_tuple[-3]
+
+
+Indexing starts from 0 from left to right and from -1 when accessing lists
+in reverse. Thus num_list[2] refers to the third element 3. and greetings
+[-2] is the second element from the end , that is 'l'.
+
+
+
+Addition gives a new sequence containing both sequences ::
+
+ num_list+var_list
+ a_string="another string"
+ greeting_string+a_string
+ t2=(3,4,6,7)
+ num_tuple+t2
+
+len function gives the length ::
+
+ len(num_list)
+ len(greeting_string)
+ len(num_tuple)
+
+Prints the length the variable.
+
+We can check the containership of an element using the 'in' keyword ::
+
+ 3 in num_list
+ 'H' in greeting_string
+ 2 in num_tuple
+
+We see that it gives True and False accordingly.
+
+Find maximum using max function and minimum using min::
+
+ max(num_tuple)
+ min(greeting_string)
+
+Get a sorted list ::
+
+ sorted(num_list)
+
+
+As a consequence of their order, we can access a group of elements in a
+sequence, together. This is called slicing and striding.
+
+First lets discuss Slicing,
+
+Given a list ::
+
+ j=[1,2,3,4,5,6]
+
+Lets say we want elements starting from 2 and ending in 5.
+
+For this we can do ::
+
+ j[1:4]
+
+The syntax for slicing is, sequence variable name square bracket first
+element index, colon, second element index. The last element however is not
+included in the resultant list::
+
+
+ j[:4]
+
+If first element is left blank default is from beginning and if last
+element is left blank it means till the end.
+
+::
+
+ j[1:]
+
+ j[:]
+
+This effectively is the whole list.
+
+Striding is similar to slicing except that the step size here is not one.
+
+Lets see by example ::
+
+ new_num_list=[1,2,3,4,5,6,7,8,9,10]
+ new_num_list[1:8:2]
+ [2, 4, 6, 8]
+
+The colon two added in the end signifies all the alternate elements. This
+is why we call this concept striding because we move through the list with
+a particular stride or step. The step in this example being 2.
+
+We have talked about many similar features of lists, strings and tuples.
+But there are many important features in lists that differ from strings and
+tuples. Lets see this by example.::
+
+ new_num_list[1]=9
+ greeting_string[1]='k'
+
+{{{ slide to show the error }}}
+
+
+
+As you can see while the first command executes with out a problem there is
+an error on the second one.
+
+Now lets try ::
+
+ new_tuple[1]=5
+
+Its the same error. This is because strings and tuples share the property
+of being immutable. We cannot change the value at a particular index just
+by assigning a new value at that position.
+
+
+We have looked at different types but we need to convert one data type into
+another. Well lets one by one go through methods by which we can convert
+one data type to other:
+
+We can convert all the number data types to one another ::
+
+ i=34
+ d=float(i)
+ d
+
+Python has built in functions int, float and complex to convert one number
+type data structure to another.
+
+::
+
+ dec=2.34
+ dec_con=int(dec)
+ dec_con
+
+
+As you can see the decimal part of the number is simply stripped to get the
+integer.::
+
+ com=2.3+4.2j
+ float(com)
+ com
+
+In case of complex number to floating point only the real value of complex
+number is taken.
+
+Similarly we can convert list to tuple and tuple to list ::
+
+ lst=[3,4,5,6]
+ tup=tuple(lst)
+ tupl=(3,23,4,56)
+ lst=list(tuple)
+
+However converting a string to a list and a list to a string is an
+interesting problem. Let's say we have a string ::
+
+ In: somestring="Is there a way to split on these spaces."
+ In: somestring.split()
+
+
+This produces a list with the string split at whitespace. Similarly we can
+split on some other character.
+
+::
+
+ In: otherstring="Tim,Amy,Stewy,Boss"
+
+How do we split on comma , simply pass it as argument ::
+
+ In: otherstring.split(',')
+
+join function does the opposite. Joins a list to make a string.::
+
+ ','.join['List','joined','on','commas']
+
+Thus we get a list joined on commas. Similarly we can do spaces.::
+
+ ' '.join['Now','on','spaces']
+
+Note that the list has to be a list of strings to apply join operation.
+
+With this we come to the end of this tutorial .
+
+Following is an (are) exercise(s) that you must do.
+
+
+
+%% %% Check if 3 is an element of the list [1,7,5,3,4]. In case
+it is change it to 21.
+::
+ l=[1,7,5,3,4]
+ 3 in l
+ l[3]=21
+ l
+
+%% %% Convert the string "Elizabeth is queen of england" to
+"Elizabeth is queen"
+::
+
+ s="Elizabeth is queen of england"
+ stemp=s.split()
+ ' '.join(stemp[:3])
+
+Please, pause the video here. Do the exercise(s) and then continue.
+
+
+This brings us to the end of the tutorial. In this tutorial we have
+discussed
+
+1. Number Datatypes , integer,float and complex
+2. Boolean and datatype and operators
+3. Sequence data types ,List,String and Tuple
+4. Accesing sequence
+5. Slicing sequences
+6. Finding length , sorting and reversing operations on sequences.
+7. Immutability.
+
+{{{ Show the "sponsored by FOSSEE" slide }}}
+
+This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+
+Hope you have enjoyed and found it useful.
+
+Thank You.
+
+
+..
+ Local Variables:
+ mode: rst
+ indent-tabs-mode: nil
+ sentence-end-double-space: nil
+ fill-column: 75
+ End:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/slides.org Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,158 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Plotting Data
+#+AUTHOR: FOSSEE
+#+DATE: 2010-09-14 Tue
+#+EMAIL: info@fossee.in
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+OPTIONS: H:1 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
+#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
+
+* Outline
+** Datatypes in Python
+*** Numbers
+*** Boolean
+*** Sequence
+** Operators in Python
+*** Arithmetic Operators
+*** Boolean Operators
+** Python Sequence Datatypes
+*** list
+*** string
+*** tuple
+
+* Numbers
+ - int
+ - float
+ - complex
+* Question 1
+ - Find the absolute value of 3+4j
+* Solution 1
+ #+begin_src python
+ abs(3+4j)
+ #+end_src python
+* Question 2
+ - What is the datatype of number 999999999999999999? Is it
+not int?
+
+* Solution 2
+ - Long
+ - Large integers numbers are internally stored in python as Long
+ datatype.
+
+
+* Boolean
+ #+begin_src python
+ In []: t=True
+ In []: f=False
+ #+end_src
+
+* Question 3
+ - Using python find sqaure root of 3?
+
+* Solution 3
+
+ - 3**0.5
+
+* Question 4
+ - Is 3**1/2 and 3**0.5 same
+* Solution 4
+ - No,One gives an int answer and the other float
+
+* Sequence Data types
+** Properties
+ - Data in Sequence
+ - Accessed using Index
+** Type
+ - list
+ - String
+ - Tuple
+
+* All are Strings
+ #+begin_src python
+ k = 'Single quote'
+ l = "Double quote contain's single quote"
+ m = '''"Contain's both"'''
+
+ #+end_src
+* Immutabilty Error
+ #+begin_src python
+ In []: greeting_string[1]='k'
+ -------------------------------------------------------
+ TypeError Traceback (most recent call last)
+
+ /home/fossee/<ipython console> in <module>()
+
+ TypeError: 'str' object does not support item assignment
+ #+end_src
+
+* Question 5
+ Check if 3 is an element of the list [1,7,5,3,4]. In case it is
+change it to 21.
+
+* Solution 5
+ #+begin_src python
+ l=[1,7,5,3,4]
+ 3 in l
+ l[3]=21
+ l
+ #+end_src
+* Question 6
+ Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is
+queen"~
+
+* Solution 6
+ #+begin_src python
+ s = "Elizabeth is queen of england"
+ stemp = s.split()
+ ' '.join(stemp[:3])
+ #+end_src
+* Summary
+ - Number Datatypes -- integer,float and complex
+ - Boolean and datatype and operators
+ - Sequence data types -- List, String and Tuple
+ - Accesing sequence
+ - Slicing sequences
+ - Finding length, sorting and reversing operations on sequences
+ - Immutability
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/slides.org.orig Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,158 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+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
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Plotting Data
+#+AUTHOR: FOSSEE
+#+DATE: 2010-09-14 Tue
+#+EMAIL: info@fossee.in
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+OPTIONS: H:1 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
+#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
+
+* Outline
+** Datatypes in Python
+*** Numbers
+*** Boolean
+*** Sequence
+** Operators in Python
+*** Arithmetic Operators
+*** Boolean Operators
+** Python Sequence Datatypes
+*** list
+*** string
+*** tuple
+
+* Numbers
+ - int
+ - float
+ - complex
+* Question 1
+ - Find the absolute value of 3+4j
+* Solution 1
+ #+begin_src python
+ abs(3+4j)
+ #+end_src python
+* Question 2
+ - What is the datatype of number 999999999999999999? Is it
+not int?
+
+* Solution 2
+ - Long
+ - Large integers numbers are internally stored in python as Long
+ datatype.
+
+
+* Boolean
+ #+begin_src python
+ In []: t=True
+ In []: f=False
+ #+end_src
+
+* Question 3
+ - Using python find sqaure root of 3?
+
+* Solution 3
+
+ - 3**0.5
+
+* Question 4
+ - Is 3**1/2 and 3**0.5 same
+* Solution 4
+ - No,One gives an int answer and the other float
+
+* Sequence Data types
+** Properties
+ - Data in Sequence
+ - Accessed using Index
+** Type
+ - list
+ - String
+ - Tuple
+
+* All are Strings
+ #+begin_src python
+ k = 'Single quote'
+ l = "Double quote contain's single quote"
+ m = '''"Contain's both"'''
+
+ #+end_src
+* Immutabilty Error
+ #+begin_src python
+ In []: greeting_string[1]='k'
+ -------------------------------------------------------
+ TypeError Traceback (most recent call last)
+
+ /home/fossee/<ipython console> in <module>()
+
+ TypeError: 'str' object does not support item assignment
+ #+end_src
+
+* Question 5
+ Check if 3 is an element of the list [1,7,5,3,4]. In case it is
+change it to 21.
+
+* Solution 5
+ #+begin_src python
+ l=[1,7,5,3,4]
+ 3 in l
+ l[3]=21
+ l
+ #+end_src
+* Question 6
+ Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is
+queen"~
+
+* Solution 6
+ #+begin_src python
+ s = "Elizabeth is queen of england"
+ stemp = s.split()
+ ' '.join(stemp[:3])
+ #+end_src
+* Summary
+ - Number Datatypes -- integer,float and complex
+ - Boolean and datatype and operators
+ - Sequence data types -- List, String and Tuple
+ - Accesing sequence
+ - Slicing sequences
+ - Finding length, sorting and reversing operations on sequences
+ - Immutability
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/basic_datatypes_and_operators/slides.tex Wed Dec 01 16:51:35 2010 +0530
@@ -0,0 +1,286 @@
+% Created 2010-11-09 Tue 15:26
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{t1enc}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Plotting Data }
+\author{FOSSEE}
+\date{2010-09-14 Tue}
+
+\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+\begin{itemize}
+
+\item Datatypes in Python
+\label{sec-1_1}%
+\begin{itemize}
+
+\item Numbers\\
+\label{sec-1_1_1}%
+\item Boolean\\
+\label{sec-1_1_2}%
+\item Sequence\\
+\label{sec-1_1_3}%
+\end{itemize} % ends low level
+
+\item Operators in Python
+\label{sec-1_2}%
+\begin{itemize}
+
+\item Arithmetic Operators\\
+\label{sec-1_2_1}%
+\item Boolean Operators\\
+\label{sec-1_2_2}%
+\end{itemize} % ends low level
+
+\item Python Sequence Datatypes
+\label{sec-1_3}%
+\begin{itemize}
+
+\item list\\
+\label{sec-1_3_1}%
+\item string\\
+\label{sec-1_3_2}%
+\item tuple\\
+\label{sec-1_3_3}%
+\end{itemize} % ends low level
+\end{itemize} % ends low level
+\end{frame}
+\begin{frame}
+\frametitle{Numbers}
+\label{sec-2}
+
+\begin{itemize}
+\item int
+\item float
+\item complex
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Question 1}
+\label{sec-3}
+
+\begin{itemize}
+\item Find the absolute value of 3+4j
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-4}
+
+\begin{verbatim}
+abs(3+4j)
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 2}
+\label{sec-5}
+
+\begin{itemize}
+\item What is the datatype of number 999999999999999999? Is it
+\end{itemize}
+
+not int?
+\end{frame}
+\begin{frame}
+\frametitle{Solution 2}
+\label{sec-6}
+
+\begin{itemize}
+\item Long
+\item Large integers numbers are internally stored in python as Long
+ datatype.
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Boolean}
+\label{sec-7}
+
+\begin{verbatim}
+In []: t=True
+In []: f=False
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 3}
+\label{sec-8}
+
+\begin{itemize}
+\item Using python find sqaure root of 3?
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Solution 3}
+\label{sec-9}
+
+
+\begin{itemize}
+\item 3**0.5
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Question 4}
+\label{sec-10}
+
+\begin{itemize}
+\item Is 3**1/2 and 3**0.5 same
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Solution 4}
+\label{sec-11}
+
+\begin{itemize}
+\item No,One gives an int answer and the other float
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Sequence Data types}
+\label{sec-12}
+\begin{itemize}
+
+\item Properties
+\label{sec-12_1}%
+\begin{itemize}
+\item Data in Sequence
+\item Accessed using Index
+\end{itemize}
+
+
+\item Type
+\label{sec-12_2}%
+\begin{itemize}
+\item list
+\item String
+\item Tuple
+\end{itemize}
+
+
+\end{itemize} % ends low level
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{All are Strings}
+\label{sec-13}
+
+\begin{verbatim}
+k = 'Single quote'
+l = "Double quote contain's single quote"
+m = '''"Contain's both"'''
+\end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Immutabilty Error}
+\label{sec-14}
+
+\begin{verbatim}
+In []: greeting_string[1]='k'
+-------------------------------------------------------
+TypeError Traceback (most recent call last)
+
+/home/fossee/<ipython console> in <module>()
+
+TypeError: 'str' object does not support item assignment
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 5}
+\label{sec-15}
+
+ Check if 3 is an element of the list [1,7,5,3,4]. In case it is
+change it to 21.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 5}
+\label{sec-16}
+
+\begin{verbatim}
+l=[1,7,5,3,4]
+3 in l
+l[3]=21
+l
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Question 6}
+\label{sec-17}
+
+ Convert the string \~{}''Elizabeth is queen of england''\~{} to \~{}''Elizabeth is
+queen''\~{}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 6}
+\label{sec-18}
+
+\begin{verbatim}
+s = "Elizabeth is queen of england"
+stemp = s.split()
+' '.join(stemp[:3])
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-19}
+
+\begin{itemize}
+\item Number Datatypes -- integer,float and complex
+\item Boolean and datatype and operators
+\item Sequence data types -- List, String and Tuple
+\item Accesing sequence
+\item Slicing sequences
+\item Finding length, sorting and reversing operations on sequences
+\item Immutability
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-20}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}
--- a/getting-started-files/pendulum.txt Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-1.0000e-01 6.9004e-01
-1.1000e-01 6.9497e-01
-1.2000e-01 7.4252e-01
-1.3000e-01 7.5360e-01
-1.4000e-01 8.3568e-01
-1.5000e-01 8.6789e-01
-1.6000e-01 8.4182e-01
-1.7000e-01 8.5379e-01
-1.8000e-01 8.5762e-01
-1.9000e-01 8.8390e-01
-2.0000e-01 8.9985e-01
-2.1000e-01 9.8436e-01
-2.2000e-01 1.0244e+00
-2.3000e-01 1.0572e+00
-2.4000e-01 9.9077e-01
-2.5000e-01 1.0058e+00
-2.6000e-01 1.0727e+00
-2.7000e-01 1.0943e+00
-2.8000e-01 1.1432e+00
-2.9000e-01 1.1045e+00
-3.0000e-01 1.1867e+00
-3.1000e-01 1.1385e+00
-3.2000e-01 1.2245e+00
-3.3000e-01 1.2406e+00
-3.4000e-01 1.2071e+00
-3.5000e-01 1.2658e+00
-3.6000e-01 1.2995e+00
-3.7000e-01 1.3142e+00
-3.8000e-01 1.2663e+00
-3.9000e-01 1.2578e+00
-4.0000e-01 1.2991e+00
-4.1000e-01 1.3058e+00
-4.2000e-01 1.3478e+00
-4.3000e-01 1.3506e+00
-4.4000e-01 1.4044e+00
-4.5000e-01 1.3948e+00
-4.6000e-01 1.3800e+00
-4.7000e-01 1.4480e+00
-4.8000e-01 1.4168e+00
-4.9000e-01 1.4719e+00
-5.0000e-01 1.4656e+00
-5.1000e-01 1.4399e+00
-5.2000e-01 1.5174e+00
-5.3000e-01 1.4988e+00
-5.4000e-01 1.4751e+00
-5.5000e-01 1.5326e+00
-5.6000e-01 1.5297e+00
-5.7000e-01 1.5372e+00
-5.8000e-01 1.6094e+00
-5.9000e-01 1.6352e+00
-6.0000e-01 1.5843e+00
-6.1000e-01 1.6643e+00
-6.2000e-01 1.5987e+00
-6.3000e-01 1.6585e+00
-6.4000e-01 1.6317e+00
-6.5000e-01 1.7074e+00
-6.6000e-01 1.6654e+00
-6.7000e-01 1.6551e+00
-6.8000e-01 1.6964e+00
-6.9000e-01 1.7143e+00
-7.0000e-01 1.7706e+00
-7.1000e-01 1.7622e+00
-7.2000e-01 1.7260e+00
-7.3000e-01 1.8089e+00
-7.4000e-01 1.7905e+00
-7.5000e-01 1.7428e+00
-7.6000e-01 1.8381e+00
-7.7000e-01 1.8182e+00
-7.8000e-01 1.7865e+00
-7.9000e-01 1.7995e+00
-8.0000e-01 1.8296e+00
-8.1000e-01 1.8625e+00
-8.2000e-01 1.8623e+00
-8.3000e-01 1.8383e+00
-8.4000e-01 1.8593e+00
-8.5000e-01 1.8944e+00
-8.6000e-01 1.9598e+00
-8.7000e-01 1.9000e+00
-8.8000e-01 1.9244e+00
-8.9000e-01 1.9397e+00
-9.0000e-01 1.9440e+00
-9.1000e-01 1.9718e+00
-9.2000e-01 1.9383e+00
-9.3000e-01 1.9555e+00
-9.4000e-01 2.0006e+00
-9.5000e-01 1.9841e+00
-9.6000e-01 2.0066e+00
-9.7000e-01 2.0493e+00
-9.8000e-01 2.0503e+00
-9.9000e-01 2.0214e+00
--- a/getting-started-files/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-Objective Questions
--------------------
-
-.. A mininum of 8 questions here.
-
-1. What function is used to open a file?
-
- Answer: ``open``
-
-#. The ``open`` function returns a
-
- a. string
- #. list
- #. file object
- #. function
-
- Answer: file object
-
-#. ``open`` function opens a file by default in write mode. T or F?
-
- Answer: False
-
-#. The ``read`` method reads a file and returns the contents
-
- a. string
- #. list
- #. file object
- #. None of the above
-
- Answer: string
-
-#. Given a file with ``hello.txt``, which looks like
- ::
-
- Hello, World!
-
- What is the value of content, at the end of this code block::
-
- f = open('hello.txt')
- pre_content = f.read()
- content = f.read()
- f.close()
-
- Answer: It is a null string.
-
-#. The following code block prints each line of ``hello.txt``::
-
- f = open('hello.txt')
- for line in f.read():
- print line
-
- True or False?
-
- Answer: False
-
-#. Given a file with ``hello.txt``, which looks like
- ::
-
- Hello, World!
-
- What is the output of ::
-
- f = open('hello.txt')
-
- for line in f:
- print line
-
- for line in f:
- print line
-
- f.close()
-
- Answer: Hello, World! is printed once.
-
- .. The actual answer should talk about blank lines, but I'm
- .. not sure if we should get into such detail.
-
- .. Should this be made a multiple-choice?
-
- .. #[[Anoop: I think it will better if we make this multiple
- choice]]
-
-#. Given a file with ``hello.txt``, which looks like
- ::
-
- Hello, World!
-
- What is the output of ::
-
- f = open('hello.txt')
-
- for line in f:
- print line
-
- f.close()
-
- for line in f:
- print line
-
- f.close()
-
- Answer: Hello, World! is printed twice.
-
-#. Given a file with ``hello.txt``, which looks like
- ::
-
- Hello, World!
-
- What is the output of ::
-
- f = open('hello')
-
- for line in f:
- print line
-
- f.close()
-
- for line in f:
- print line
-
- f.close()
-
- Answer: IOError - No such file or directory: 'hello'
-
-
-Larger Questions
-----------------
-
-.. A minimum of 2 questions here.
-
-1. What does ``f.read(size)`` do?
-
-#. Print every alternate line of a file, starting at the first line.
-
-#. Print the file in reverse. Starting from the last line to the
- first.
--- a/getting-started-files/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-\textbf{Getting Started -- files}
-
-\lstinline|f = open('filename')| returns a file object. \lstinline|f|
-can be used to perform further operations on the file.
-
-\lstinline|f.read()| reads the whole file and returns the contents.
-
-\lstinline|f.close()| closes the file.
-
-\lstinline|for line in open('filename'):| -- iterate over the file
-line-by-line.
-
--- a/getting-started-files/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-.. Objectives
-.. ----------
-
-.. By the end of this tutorial, you will be able to
-.. 1. Open and read the contents of a file.
-.. #. Read files line by line.
-.. #. Read all the contents of the file at once.
-.. #. Close open files.
-
-.. Prerequisites
-.. -------------
-
-.. 1. getting started with ipython
-.. #. getting started with lists
-.. #. getting started with for
-
-.. Author : Puneeth
- Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in>
- External Reviewer :
- Language Reviewer : Bhanukiran
- Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05]
-
-Script
-------
-
-{{{ Show the slide containing title }}}
-
-Hello Friends. Welcome to the tutorial on getting started with files.
-
-{{{ Show the outline for this tutorial }}}
-
-In this tutorial we shall learn to read files, and do some basic
-actions on the file, like opening and reading a file, closing a
-file, iterating through the file line-by-line, and appending the
-lines of a file to a list.
-
-{{{ switch back to the terminal }}}
-
-As usual, we start IPython, using
-::
-
- ipython -pylab
-
-Let us first open the file, ``pendulum.txt`` present in
-``/home/fossee/``.
-::
-
- f = open('/home/fossee/pendulum.txt')
-
-``f`` is called a file object. Let us type ``f`` on the terminal to
-see what it is.
-::
-
- f
-
-The file object shows, the file which is open and the mode (read
-or write) in which it is open. Notice that it is open in read only
-mode, here.
-
-We shall first learn to read the whole file into a single
-variable. Later, we shall look at reading it line-by-line. We use
-the ``read`` method of ``f`` to read, all the contents of the file
-into the variable ``pend``.
-::
-
- pend = f.read()
-
-Now, let us see what is in ``pend``, by typing
-::
-
- print pend
-
-We can see that ``pend`` has all the data of the file. Type just ``pend``
-to see more explicitly, what it contains.
-::
-
- pend
-
-Following is an exercise that you must do.
-
-{{ show slide with Question 1 }}
-
-%%1%% Split the variable into a list, ``pend_list``, of the lines in
-the file. Hint, use the tab command to see what methods the string
-variable has.
-
-Please, pause the video here. Do the exercise and then continue.
-
-{{ show slide with Solution 1 }}
-
-::
-
- pend_list = pend.splitlines()
-
- pend_list
-
-Now, let us learn to read the file line-by-line. But, before that we
-will have to close the file, since the file has already been read till
-the end.
-
-Let us close the file opened into f.
-::
-
- f.close()
-
-Let us again type ``f`` on the prompt to see what it shows.
-::
-
- f
-
-Notice, that it now says the file has been closed. It is a good
-programming practice to close any file objects that we have
-opened, after their job is done.
-
-Let us, now move on to reading files line-by-line.
-
-Following is an exercise that you must do.
-
-%%2%% Re-open the file ``pendulum.txt`` with ``f`` as the file object.
-
-Please, pause the video here. Do the exercise and then continue.
-
-We just use the up arrow until we reach the open command and issue
-it again.
-::
-
- f = open('/home/fossee/pendulum.txt')
-
-Now, to read the file line-by-line, we iterate over the file
-object line-by-line, using the ``for`` command. Let us iterate over
-the file line-wise and print each of the lines.
-::
-
- for line in f:
- print line
-
-As we already know, ``line`` is variable, sometimes called the loop
-variable, and it is not a keyword. We could have used any other
-variable name, but ``line`` seems meaningful enough.
-
-Instead of just printing the lines, let us append them to a list,
-``line_list``. We first initialize an empty list, ``line_list``.
-::
-
- line_list = [ ]
-
-Let us then read the file line-by-line and then append each of the
-lines, to the list. We could, as usual close the file using
-``f.close`` and re-open it. But, this time, let's leave alone the
-file object ``f`` and directly open the file within the for
-statement. This will save us the trouble of closing the file, each
-time we open it.
-
-::
-
- for line in open('/home/fossee/pendulum.txt'):
- line_list.append(line)
-
-Let us see what ``line_list`` contains.
-::
-
- line_list
-
-Notice that ``line_list`` is a list of the lines in the file, along
-with the newline characters. If you noticed, ``pend_list`` did not
-contain the newline characters, because the string ``pend`` was
-split on the newline characters.
-
-Using some string methods, that we shall look at in the tutorial on
-strings, we can strip out the newline characters from the lines.
-
-.. #[[Anoop: I think the code that are required to be typed can be
- added to the slide.]]
-
-{{{ show the summary slide }}}
-
-That brings us to the end of this tutorial. In this tutorial we
-have learnt to open and close files, read the data in the files as
-a whole, using the read command or reading it line by line by
-iterating over the file object.
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-Thank you!
-
-
--- a/getting-started-files/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER: \usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Getting started with files
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- - Opening and reading contents of a file
- - Closing open files
- - Reading all the contents of the file at once
- - Reading files line by line
-* Question 1
- Split the variable into a list, =pend_list=, of the lines in the
- file. Hint, use the tab command to see what methods the string
- variable has.
-* Solution 1
- #+begin_src python
- In []: pend_list = pend.splitlines()
-
- In []: pend_list
- #+end_src
-* Question 2
- Re-open the file =pendulum.txt= with =f= as the file object.
-* Solution 2
- #+begin_src python
- In []: f = open('/home/fossee/pendulum.txt')
- #+end_src
-* Summary
- - Opening a file using =open= function
- - Reading all the contents of the file at once using =read()= method
- - Closing open files using the =close= method
- - Reading files line by line by iterating using a =for= loop
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-#+end_latex
-
-
--- a/getting-started-files/slides.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-% Created 2010-10-21 Thu 14:35
-\documentclass[presentation]{beamer}
-\usepackage[latin1]{inputenc}
-\usepackage[T1]{fontenc}
-\usepackage{fixltx2e}
-\usepackage{graphicx}
-\usepackage{longtable}
-\usepackage{float}
-\usepackage{wrapfig}
-\usepackage{soul}
-\usepackage{t1enc}
-\usepackage{textcomp}
-\usepackage{marvosym}
-\usepackage{wasysym}
-\usepackage{latexsym}
-\usepackage{amssymb}
-\usepackage{hyperref}
-\tolerance=1000
-\usepackage[english]{babel} \usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-\usepackage{listings}
-\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-\providecommand{\alert}[1]{\textbf{#1}}
-
-\title{Getting started with files}
-\author{FOSSEE}
-\date{}
-
-\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-\begin{document}
-
-\maketitle
-
-
-
-
-
-
-
-
-
-\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-
-\begin{itemize}
-\item Opening and reading contents of a file
-\item Closing open files
-\item Reading all the contents of the file at once
-\item Reading files line by line
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Question 1}
-\label{sec-2}
-
- Split the variable into a list, \texttt{pend\_list}, of the lines in the
- file. Hint, use the tab command to see what methods the string
- variable has.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
-\label{sec-3}
-
-\begin{verbatim}
-In []: pend_list = pend.splitlines()
-
-In []: pend_list
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Question 2}
-\label{sec-4}
-
- Re-open the file \texttt{pendulum.txt} with \texttt{f} as the file object.
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 2}
-\label{sec-5}
-
-\begin{verbatim}
-In []: f = open('/home/fossee/pendulum.txt')
-\end{verbatim}
-\end{frame}
-\begin{frame}
-\frametitle{Summary}
-\label{sec-6}
-
-\begin{itemize}
-\item Opening a file using \texttt{open} function
-\item Reading all the contents of the file at once using \texttt{read()} method
-\item Closing open files using the \texttt{close} method
-\item Reading files line by line by iterating using a \texttt{for} loop
-\end{itemize}
-\end{frame}
-\begin{frame}
-\frametitle{Thank you!}
-\label{sec-7}
-
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}
- \begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/getting-started-ipython/questions.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-Objective Questions
--------------------
-
-.. A mininum of 8 questions here (along with answers)
-
-1. ``ipython`` is a programming language similar to Python. T or F?
-
- Answer: False
-
-#. Which key combination quits ``ipython``?
-
- a. Ctrl + C
- #. Ctrl + D
- #. Alt + C
- #. Alt + D
-
- Answer: Ctrl + D
-
-#. Which key combination raises a ``keyboard interrupt``
-
- a. Ctrl + C
- #. Ctrl + D
- #. Alt + C
- #. Alt + D
-
- Answer: Ctrl + C
-
-#. If you have typed the following commands::
-
- 1 + 2
- 3 - 5
- 1 - 6
- 5 + 5
- 3 * 2
-
- What is the result of the following actions.
-
- * up arrow 3 times
- * backspace 4 times
-
- Answer: 1
-
-#. If you have typed the following commands::
-
- 1 + 2
- 3 - 5
- 1 - 6
- 5 + 5
- 3 * 2
-
- What is the result of the following actions.
-
- * type ``1``
- * up arrow 2 times
-
- Answer: 1 + 2
-
-#. If you have typed the following commands::
-
- 1 + 2
- 3 - 5
- 1 - 6
- 5 + 5
- 3 * 2
-
- What is the result of the following actions.
-
- * type ``5``
- * up arrow 2 times
-
- Answer: 5 + 5
-
-#. If you have typed the following commands::
-
- 1 + 2
- 3 - 5
- 1 - 6
- 5 + 5
- 3 * 2
-
- What is the result of the following actions.
-
- * type ``1``
- * up arrow 1 time
- * left arrow 3 times
- * up arrow key
-
- Answer: 1 - 6
-
-#. If you have typed the following commands::
-
- 1 + 2
- 3 - 5
- 1 - 6
- 5 + 5
- 3 * 2
-
- What is the result of the following actions.
-
- * type ``1``
- * up arrow 1 time
- * left arrow 3 times
- * down arrow key
-
- Answer: 1 - 6
-
-#. If the following are only commands available in ``ipython``
-
- * zebra
- * zenith
- * zest
-
- What are the commands listed by typing ``z`` and hitting the <TAB> key
-
- Answer: zebra, zenith, zest
-
-#. If the following are only commands available in ``ipython``
-
- * zebra
- * zenith
- * zest
-
- ``z`` is auto-completed to ``ze`` by hitting the <TAB> key after typing
- ``z``. T or F?
-
- Answer: True
-
-
-#. If the following are only commands available in ``ipython``
-
- * zebra
- * zenith
- * zest
-
- What are the commands listed by typing ``zeb`` and hitting the <TAB> key
-
- Answer: zebra
-
-#. If the following are only commands available in ``ipython``
-
- * zebra
- * zenith
- * zest
-
- What are the commands listed by typing ``z`` and hitting the <TAB> key
-
- Answer: zebra, zenith, zest
-
-#. Which character is used at the end of a command, in ``ipython`` to display
- the documentation.
-
- a. _
- #. ?
- #. !
- #. &
-
- Answer: ?
-
-#. What happens if the size of documentation text is more than that can be
- accomodated on your screen.
-
- a. The whole documentation is printed and it is auto scrolled to bottom
- #. Only a part of documentation is shown and the remaining can be scrolled
- through using up and down arrows
- #. Only a part of documentation is shown and cursor returns to ``In`` prompt
-
- Answer: Only a part of documentation is shown and the remaining can be
- scrolled through using up and down arrows
-
-#. Which key is used to quit the documentation that runs several pages and
- return to the ``ipython`` prompt.
-
- a. a
- #. c
- #. q
- #. <ESC>
-
- Answer: q
-
-Larger Questions
-----------------
-
-.. A minimum of 2 questions here (along with answers)
-..[[Anand: Long answer questions required]]
-1. Question 1
-2. Question 2
--- a/getting-started-ipython/quickref.tex Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-\textbf{Getting started -- \texttt{ipython}}
-
-To start \lstinline|ipython| with \lstinline|pylab|:\\
-\lstinline| $ ipython -pylab| %$
-
-To exit: \lstinline|^D| (Ctrl-D)
-
-To interrupt: \lstinline|^C| (Ctrl-C)
-
-Tab completes partial commands
-
-\texttt{?} to look up documentation.
-
-Arrow keys to navigate the history.
--- a/getting-started-ipython/script.rst Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-.. Objectives
-.. ----------
-
-.. At the end of this tutorial, you will be able to
-
-.. 1. invoke the ``ipython`` interpreter.
-.. #. quit the ``ipython`` interpreter.
-.. #. navigate in the history of ``ipython``.
-.. #. use tab-completion.
-.. #. look-up documentation of functions.
-.. #. interrupt incomplete or incorrect commands.
-
-.. Prerequisites
-.. -------------
-
-.. should have ``ipython`` and ``pylab`` installed.
-
-.. Author : Puneeth
- Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in>
- Language Review : Bhanukiran
- External Reviewer :
- Checklist OK? : <put date stamp here, if OK> [2010-10-05]
-
-
-Script
-------
-
-{{{ Show the slide containing title }}}
-
-Hello Friends and Welcome to the tutorial on getting started with
-``ipython``.
-
-{{{ Show slide with outline }}}
-
-This tutorial will cover the basic usage of the ``ipython``
-interpreter. The following topics would be covered.
-
-IPython is an enhanced Python interpreter that provides features like
-tabcompletion, easier access to help and lot of other functionality
-which are not available in the vanilla Python interpreter.
-
-First let us see how to invoke the ``ipython`` interpreter.
-
-We type
-::
-
- ipython
-
-at the terminal prompt to invoke the ipython interpreter.
-
-We get a prompt with ``In [1]:`` after getting some information about
-the version of Python installed and some help commands.
-
-If you get an error saying something like ``ipython is not
-installed``, refer to the tutorial on how to install the packages
-required for this course.
-
-Now, to quit the ipython interpreter, type Ctrl-D. You are prompted
-asking if you really want to exit, type y to say yes and quit ipython.
-
-Start ipython again, as you did before.
-
-The prompt that you have says ``In [1]``. ``In`` stands for input and the
-ipython interpreter is ready to accept input from you.
-
-Now let us see, how we can type some commands into the interpreter.
-
-Start with the simplest thing, addition.
-
-Let's type
-::
- 1+2
-
-at the prompt. IPython promptly gives back the output as 3. Notice
-that the output is displayed with an ``Out[1]`` indication.
-
-.. #[[Anoop: I think we can illustrate In [] and Out[] in slides]]
-.. #[[Puneeth: I think we can do that on the terminal?]]
-
-Let's try out few other mathematical operations.
-::
-
- 5 - 3
- 7 - 4
- 6 * 5
-
-Now let's ``print 1+2``. Instead of typing the whole thing, we make
-use of the fact that IPython remembers the history of the commands
-that you have already used. We use the up arrow key to go back the
-command ``1+2``. We then use the left-arrow key to navigate to the
-beginning of the line and add the word ``print`` and a space. Then hit
-enter and observe that the interpreter prints out the value as 3,
-without the Out[] indication.
-
-Now, let's change the previous command ``print 1+2`` to ``print
-10*2``. We use the up arrow again to navigate to the previous command
-and use the left arrow key to move the cursor on to the + symbol and
-then use the delete key to remove it and type 0 and * to change the
-expression as required. We hit enter to see the output of
-``print``.
-
-Now, let's say we want to use the function ``round``. We type ``ro``
-at the prompt and hit the tab key. As you can see, IPython
-completes the command. This feature is called the tab-completion.
-
-Now, we remove all the characters and just type ``r`` and then hit
-tab. IPython does not complete the command since there are many
-possibilities. It just lists out all the possible completions.
-
-Following is an exercise that you must do.
-
-%%1%% Type ``ab`` and hit tab to see what happens. Next, just type
-``a`` and hit tab to see what happens.
-
-Please, pause the video here. Do the exercise and then continue.
-
-``ab`` tab completes to ``abs`` and ``a<tab>`` gives us a list of all
-the commands starting with a.
-
-Now, let's see what these functions are used for. We will use the
-help features of ipython to find this out.
-
-.. #[[Anoop: Another slide which says about ? mark and round? etc, as
- few people cannot just follow by listening (like me) :)]]
-
-.. #[Punch: These things are shown on the terminal. I feel we don't
-.. need slide, here I guess.]
-
-To get the help of any function, we first type the function, ``abs``
-in our case and then add a ? at the end and hit enter.
-
-As the documentation says, ``abs`` accepts a number as an input and
-returns it's absolute value.
-
-We say,
-::
-
- abs(-19)
-
- abs(19)
-
-We get 19, as expected, in both the cases.
-
-Does it work for decimals (or floats)? Let's try typing abs(-10.5)
-and we do get back 10.5.
-
-Following is an exercise that you must do.
-
-%%2%% Look-up the documentation of ``round`` and see how to use it.
-
-Please, pause the video here. Do the exercise and then continue.
-
-::
-
- round?
-
-If you notice, there are extra square brackets around the ``ndigits``.
-This means that ``ndigits`` is optional and 0 is the default value.
-Optional parameters are shown in square brackets anywhere in Python
-documentation.
-
-The function ``round``, rounds a number to a given precision.
-
-Following are exercises that you must do.
-
-%%3%% Check the output of::
-
- round(2.48)
- round(2.48, 1)
- round(2.48, 2)
-
- round(2.484)
- round(2.484, 1)
- round(2.484, 2)
-
-Please, pause the video here. Do the exercises and then continue.
-
-We get 2.0, 2.5 and 2.48, which are what we expect.
-
-Let's now see how to correct typing errors that we make while typing at
-the terminal. As already shown, if we haven't hit the enter key
-already, we could navigate using the arrow keys and make deletions
-using delete or backspace key and correct the errors.
-
-Let's now type round(2.484 and hit enter, without closing the
-parenthesis. We get a prompt with dots. This prompt is the
-continuation prompt of ``ipython``. It appears, the previous line is
-incomplete in some way. We now complete the command by typing, the
-closing parenthesis and hitting enter. We get the expected output of
-2.5.
-
-In other instances, if we commit a typing error with a longer and more
-complex expression and end up with the continuation prompt, we can
-type Ctrl-C to interrupt the command and get back the ``ipython`` input
-prompt.
-
-Following is an exercise that you must do.
-
-%%4%% Try typing round(2.484, and hit enter. and then cancel the
-command using Ctrl-C. Then, type the command, round(2.484, 2) and
-resume the video.
-
-Please, pause the video here. Do the exercises and then continue.
-
-::
-
- round(2.484
- ^C
-
- round(2.484, 2)
-
-This brings us to the end of the tutorial on getting started with
-``ipython``.
-
-.. #[[Anoop: add slides for interrupts, navigating history, I feel
- even a single point will also do]]
-
-.. #[Puneeth: I don't feel these things cannot be shown on a slide.]
-
-In this tutorial we have learnt, how to
-{{{ show the outline/summary slide. }}}
-
- 1. invoke the ``ipython`` interpreter.
- #. quit the ``ipython`` interpreter.
- #. navigate in the history of ``ipython``.
- #. use tab-completion.
- #. look-up documentation of functions.
- #. interrupt incomplete or incorrect commands.
-
-{{{ Show the "sponsored by FOSSEE" slide }}}
-
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
-
-Hope you have enjoyed and found it useful.
-Thank you!
--- a/getting-started-ipython/slides.org Wed Nov 17 23:24:57 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-#+BEAMER_FRAME_LEVEL: 1
-
-#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
-#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
-#+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
-
-#+LaTeX_CLASS: beamer
-#+LaTeX_CLASS_OPTIONS: [presentation]
-
-#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
-#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
-
-#+LaTeX_HEADER:\usepackage{listings}
-
-#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
-#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
-#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-
-#+TITLE: Getting Started -- ~ipython~
-#+AUTHOR: FOSSEE
-#+EMAIL:
-#+DATE:
-
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE: en
-#+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
- + invoke the ~ipython~ interpreter
- + quit the ~ipython~ interpreter
- + navigate in the history of ~ipython~
- + use tab-completion
- + look-up documentation of functions
- + interrupt incomplete or incorrect commands
-* Question 1
- Type =ab= and hit tab to see what happens. Next, just type =a= and
- hit tab to see what happens.
-* Solution 1
- =ab= tab completes to =abs= and =a<tab>= gives us a list of all the
- commands starting with a.
-* Question 2
- Look-up the documentation of =round= and see how to use it.
-* Solution 2
- =round?=
-* Question 3
- Check the output of
- #+begin_src python
- round(2.48)
- round(2.48, 1)
- round(2.48, 2)
-
- round(2.484)
- round(2.484, 1)
- round(2.484, 2)
- #+end_src
- Look-up the documentation of =round= and see how to use it.
-* Solution 3
- We get 2.0, 2.5 and 2.48, which are what we expect.
-* Question 4
- Try typing =round(2.484=, and hit enter. and then cancel the command
- using Ctrl-C. Then, type the command, =round(2.484, 2)= and resume
- the video.
-* Solution 4
- #+begin_src python
- round(2.484
- ^C
-
- round(2.484, 2)
- #+end_src
-
-
-
-* Summary
- + invoking and quitting the ~ipython~ interpreter
- + navigating the history
- + using tab-completion to work faster
- + looking-up documentation using ~?~
- + sending keyboard interrupts using ~Ctrl-C~
-
-* Thank you!
-#+begin_latex
- \begin{block}{}
- \begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
- \end{center}