Removed all files to start working on ID based spoken tutorials scripts.
--- a/arrays.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-* Arrays
-*** Outline
-***** Introduction
-******* What do we want to do
-********* We shall use arrays (mentioned before) which
-********* shall be used for matrices in future
-******* Arsenal Required
-********* working knowledge of lists
-***** Initializing matrices
-******* Entering element-wise
-******* using special functions
-***** Accessing and Changing elements
-******* Slicing??
-******* Striding??
-***** {{Simple operations??}}
-*** Script
- Welcome to the Tutorial on arrays.
-
- As mentioned in [the previous tutorial] arrays are much faster and
- more efficient. In this tutorial we shall look at creating arrays,
- accessing elements and changing them.
-
- ---
-
- Let's start with creating simple arrays. We've already seen how to
- convert lists to arrays. Inputting a new array is similar to that.
-
- In []: a = array([5, 8, 10, 13])
-
- Type /a/, to see what it is.
-
- In []: a
-
- We enter a multi-dimensional array this way -
-
- In []: c = array([[11,12,13],
- [21,22,23],
- [31,32,33]])
-
- To see what c is, we just type c in the prompt.
-
- In []: c
-
- To see the dimensions of the array c, we use c.shape
- In []: c.shape
-
- Now let us look at some special methods of creating an
- array. There are various functions that allow us to create special
- arrays.
-
- The first one we shall look at is, /arange/. /arange/ is similar to
- the range command, except that it returns an array and accepts
- float arguments.
-
- In []: a = arange(10)
-
- In []: a
- This is the array we just created.
-
- In []: a.shape
- Note that /a/ is one dimensional and has 10 elements, as expected.
-
- We could also use a.shape to change the shape of the array a.
- In []: a.shape = 2,5
- Note that the total size of new array must be unchanged.
-
- We type a, to see what it looks like
- In []: a
-
- ones command can be used to get an array with all the entries as
- ones. We pass it the shape of the array that we require.
-
- In []: b = ones((3, 4))
-
- Look at b, by printing it out.
- In []: b
-
- To create an array with all entries as ones, with it's shape
- similar to an already existing array, we use the ones_like
- command.
- In []: b = ones_like(a)
-
- zeros and zeros_like are similar commands that can give you arrays
- with all zeros. empty and empty_like give you empty arrays (arrays
- with no initialization done.)
-
- In []: b = zeros((3, 4))
- In []: b = zeros_like(a)
-
- The identity command can be used to obtain a square array with
- ones on the main diagonal.
-
- In []: identity(3)
-
- To obtain a 2-D array, that is not necessarily square, eye command
- can be used. Look at the documentation of eye (using eye?) for
- more info.
-
- ---
-
- Now that we have learnt how to create arrays, let's move on to
- accessing elements and changing them.
-
- Let's work with the c, array which we had already created.
-
- In []: c
-
- Let's say we want to access the element 23 in c, we say
-
- In []: c[1][2]
- Note that this is similar to accessing an element inside a list of
- lists. Also, note that counting again starts from 0.
-
- But arrays provide a more convenient way to access the elements.
- In []: c[1, 2]
-
- Now, we can also change the element using a simple assignment.
- In []: c[1, 2] = -23
-
- Let's look at accessing more than one elements at a time. We begin
- with accessing rows.
- In []: c[1] gives us the second row. (counting starts from 0)
-
- To get a column, we use a syntax that is similar to the one used
- to access a single element.
- In []: c[:,1], gives us the first column.
-
- The colon specifies that we wish to obtain all elements in that
- dimension from the array.
-
- So, we could use a more explicit way to access the second row of
- the array.
- In []: c[1,:]
-
- The colon can be used to access specific portions of the array,
- similar to the way we do with lists.
- In []: c[1,1:3]
- Observe that we get the second and third columns from the second
- row. As with lists, the number after the colon is excluded when
- slicing a portion of the array.
-
- In []: c[1:3,1]
- Now, we get the second and third rows from the first column.
-
- In []: c[1:3,1:3]
- We get the second and third rows and the second and third
- columns.
-
- The numbers before and after the colons are optional. If the
- number before the colon is omitted, it is assumed to be zero by
- default. If the element after the colon is omitted, it is assumed
- to be until the end.
-
- In []: c[1:, 1:]
- This is essentially similar to the previous example. We are using
- the default value i.e, the end, instead of specifying 3,
- explicitly.
-
- In []: c[:2, :2]
- We have omitted specifying the zero before the colon, explicitly.
-
- ---
-
- You may have observed the similarity of the semi-colon notation to
- the notation used in lists. As expected, the semi-colon notation
- also provides a way to specify a jump. This {concept/idea} is
- termed as Striding.
-
- To get every alternate row of c, starting from the first one, we say
- In []: c[::2,:]
-
- To get every alternate row of c, starting from the second one, we
- say
- In []: c[1::2,:]
-
-
- In []: c[:,::2]
- In []: c[::2,::2]
-
- ---
-
- We come to the end of this tutorial on arrays. In this tutorial,
- you've learnt how to create arrays and access, change elements.
-
- Thank you.
-
-*** Notes
--- a/arrays.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,196 +0,0 @@
-Hello friends and welcome to this tutorial on Matrices.
-
-In python all matrix operations are done using arrays.
-
-We saw in the previous session that arrays are better suited for mathematical operations. We saw this in the context of simple statistical functions such as mean.
-
-In this session we shall see how to perform efficient matrix operations using arrays. We will create arrays, initialize them, manipulate them and perform simple image processing using them. For this tutorial we shall need the lena.png image. Hope you have the image with you.
-
-Let's now start off. As you can see our lena image is on the desktop, so first let's navigate to the desktop by cd Desktop.
-
-Let's now start Ipython, using the command python -pylab
-
-First things first, let's start by creating a normal array.
-
-Type:
-p equal to array([5, 8, 10, 13])
-
-let's check the value of a by typing
-p
-Note how python displays an array, compared to a list.
-
-Here p is single dimension array, that is it has only one row. Let us now create a multi-dimensional array.
-
-Type:
-
-q = array([[11,12,13], [21,22,23], [31,32,33]])
-
-both p and q are arrays but with different dimensions or shape
-we can check shape of arrays by using shape attribute of arrays.
-p.shape
-q.shape
-
-A few array initialization methods are also available to make life easier;
-say we want to create an array of size 3x4 with all the elements initialized to 1, we use
-b = ones((3, 4))
-and b is
-b
-similarly, suppose we already have an array, and we want to create another array with the same shape but with initial values equal to one, for eg, to get an array similar in shape to the array 'q' but with all elements as 1 we type:
-d = ones_like(q)
-and d is a 3x3 array with all values equal to 1
-
-Similarly there are functions like zeros and zeros_like which initialize array with all values being 0. One more useful function available is 'identity', it create unit matrix of given order
-i = identity(3)
-i
-
-Note that identity takes just one argument since identity matrix is always a square matrix.
-
-----------------
-Now that we have covered creation of arrays, we shall see how to access and change values of particular elements.
-Remember we created a 3x3 matrix earlier,
-q
-
-to access the element 23 we type
-q[1][2]
-
-It is at the second row of the third column of the matrix/array q. Note that index values of arrays also start from 0.
-Alternatively, the more popular way of doing the same is
-q[1, 2]
-
-here ',' is used as separator for row and column value. Similarly any value from the array can be accessed.
-
-to access particular row completely we specify the row value alone:
-q[1]
-This gives us the entire second row.
-
-We can assign a new value to an element, the same way we accessed it. For eg.,
-q[1, 1] = -22
-q
-
-One of the most powerful aspects of a high-level language like python is the way it supports matrix operations. We can use them like we do it maths rather than think of them as elements like a programmer.
-
-For example to change a whole row, we type:
-q[1] = 0
-q
-as we can see, all elements of the second row are now 0
-
-In order to access a column, we need to syntactically indicate that the number given is the column index rather than the row index. In other words we need a placeholder for the row position. We cannot use space. That is we cannot say q[, 1] as that would be a syntax error ( q[m, n] being the method to access an _element_).
-
-We have to say all rows and a column(s) by extending the slice notation seen earlier.
-q[:,2]
-returns the third column.
-Here the ':' part specifies the row numbers of the slice; as we have seen before by leaving the from and to parts of the slice empty we effectively say ALL. Thus q[:, n] stands for a matrix which is the submatrix obtained by taking all rows and column n+1.
-
-The row reference q[1] can also be written as q[1,:]
-
-As we have seen ':' takes two values namely start and end. As before rows or columns starting from 'start' till 'end' --excluding end-- will be returned. Lets try some examples:
-q [0:2,:]
-results in a matrix which is rows 0 and 1 and all columns. Note here that 'end', in this case, '2' will not be included in resulting matrix.
-
-Similarly q[1:3,:]
-gives second and third rows.
-
-q[:, 0:2] gives us first two columns
-
-This manner of accessing chunks of arrays is also known as 'slicing'. Since the idea is the same as slicing for lists the name is also the same.
-
-As noted the default values for slices carry over.
-Thus
-q[:, :2]
-gives us the first two columns
-
-q[:, 1:]
-returns all columns excluding the 0th column.
-
-q[1:, :2]
-returns first two columns of all rows excepting the 0th row.
-
-When slicing lists we saw the idea of striding. Recall that if L is a list,
-L[start : stop : step],
-produces a new list whose first element is L[start] and has all elements whose index is start + n * step; stop signals the last index _before_ which we should stop.
-
-Matrices also support striding--that is skip, rows or columns by a certain interval.
-We add one more ':' to row or column part to specify a step size.
-Let us type
-q[:, ::2]
-and see what is shown.
-The first colon specifies that we pick all rows, the comma signals that we start specifying columns. The empty places indicate defaults. That is start from the 0th and go to the end. The presence of step--in this case 2--tells us that we will select alternate columns. Thus we q[:, ::2] extracts all rows and alternate columns starting with 0th column.
-
-q[::2,:]
-returns a 2x3 matrix with the first and the third row.
-
-q[::2, ::2]
-gives us a 2x2 array with the first and the third rows and first and third columns.
-
-Lets us use slicing and striding for doing some basic image manipulation
-
-pylab has a function named imread to read images. We shall use lena.png image for our experimentation. Its there on desktop.
-
-a = imread('lena.png')
-Now a is an array with the RGB and Alpha channel values of each pixel
-a.shape
-tells us that
-it is an 512x512x4 array.
-
-to view the image write
-imshow(a)
-
-lets try to crop the image to top left quarter. Since a is an array we can use slicing to get the top left quarter by
-imshow(a[:256,:256]) (half of 512 is 256)
-
-Let's crop the image so that only her face is visible. And to do that we'll need some rough estimates of the coordinates of the face.
-imshow(a)
-now move your mouse pointer over the image, it gives us x, y coordinates of the mouse pointer's current location. With this we can get rough estimate of lena's face. We observe that Lena's face begins from somewhere around 200, 200 and ends at 400, 400. Now cropping to these boundaries is simple
-imshow(a[200:400, 200:400])
-
-Next we shall try striding on this image. We shall resize the image by skipping alternate pixels. We have already seen how to skip alternate elements so,
-imshow(a[::2, ::2])
-note that the size of image is just 256x256.
-------------------
-
-Till now we have covered initializing and accessing elements of arrays. Now we shall look at other manipulations for arrays. We start by creating a 4x4 array
-
-a = array([[ 1, 1, 2, -1],[ 2, 5, -1, -9], [ 2, 1, -1, 3], [ 1, -3, 2, 7]])
-a
-
-To get transpose of this matrix write
-a.T
-
-The sum() function returns sum of all the elements of a matrix.
-sum(a)
-
-let's create one more array for checking more operations
-b = array([[3,2,-1,5], [2,-2,4,9], [-1,0.5,-1,-7], [9,-5,7,3]])
-
-+ takes care of matrix additions
-a + b
-
-lets try multiplication now,
-a * b returns a new matrix whose elements are products of corresponding elements. THIS IS NOT matrix multiplication.
-
-To get the usual product of matrices a and b we use
-dot(a, b)
-
-To get the inverse of a matrix we use,
-
-inv(a)
-
-det(a) returns determinant of matrix a
-
-we shall create an matrix e
-e = array([[3,2,4],[2,0,2],[4,2,3]])
-and then to evaluate eigenvalues of the same.
-eig(e)
-returns both eigen values and eigen vector of given matrix
-to get only eigen values use
-eigvals(e)
-
-This brings us to end of this session. We have covered Matrices
-Initialization
-Slicing
-Striding
-A bit of image processing
-Functions available for arrays
-
-Thank you
-
--- a/basic-plot.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,206 +0,0 @@
-* Script
-
-*Hello and welcome to the tutorial on Basic Plotting using Python.
-
-*The intended audience for this tutorial are Engineering, mathematics and science teachers and students
-
-*In this tutorial, we will cover the basics of the Plotting features available in Python.
-For this we shall use Ipython and pylab.
-Ipython is An Enhanced Interactive Python interpreter. It provides additional features like tab completion,easier access to help , and many other useful features which are not present in the vanilla Python interpreter.
-Pylab is python library which provides plotting functionality.
-
-I am assuming that both Ipython and Pylab are installed on your system. If not please refer to our tutorial on how to install IPython and pylab.
-
-*On your terminal type in the command
-$ ipython -pylab
-press RETURN
-
-We will first start with the customary Hello world program by writing:
-
-In []: print 'hello world'
-
-Voila we have got hello world as the output
-
-To exit ipython press Ctrl-D.
-
-*Now we will get back to plotting.
-
-type again :
-$ ipython -pylab
-press RETURN
-
-In order to plot, we need a set of points. Let us create a sequence of equally spaced points starting from 0 to 2*pi. For this we use linspace
-
-Type:
-In []: x = lins<Tab> This is an Ipython feature that will auto-suggest the word
-
-In [] x=linspace( RETURN
-Ouch! I made a mistake . As you can see I made the mistake of not writing command correctly
-and Ipython changed the prompt . To get the old prompt back press crtl-c
-
-In []: x = linspace(0, 2*pi, 100)
-
-*To know more about any function, in this case say, for 'linspace' you can type ? after it .
-
-In []: linspace?
-
-It shows documentation related to linspace function. 'help' gives details about arguments to be passed, return values and also some examples on usage. You can scroll the help using up, and down arrows keys.
-To exit from the help menu type 'q'.
-
-*As you can see linspace can take three parameters the starting point, the ending point and the number of points.
-
-Let us see what x contains now. Type 'x' and hit enter.
-
-We see that x is a sequence of numbers from 0 to 2*pi. We can check the length of x by typing
-
-In []: len(x)
-
-To obtain the plot we use,
-In []: plot(x, sin(x))
-***
-As you can see a plot has appeared on the screen.
-***
-
-The plot has the default color and line properties.
-
-In this case we have used two commands
-'pi' and 'sin' these come from 'pylab' library called using -pylab.
-
-*Now that we have a basic plot, we can label and title the plot.
-In []: xla<TAB>bel('x') will add a label to the x-axis. Note that 'x' is enclosed in quotes.
-Similarly
-In []: ylabel('sin(x)') adds a label to the y-axis.
-To add a title to plot we simply use
-In []: tit<TAB>le('Sinusoid').
-
-Hmm we also got the axis's nicely labeled and the plot titled but there is still a important detail left.That might leave a teacher unsatisfied, it lacks a legend.
-
-Add a legend to the plot by typing
-In []: legend(['sin(x)'])
-
-We can modify previous command to specify the location of the legend, by passing an additional argument to the function.
-
-To go to previous command, we can use 'UP Arrow key' and 'DOWN' will take us back.
-
-Once you start editing a previous command and then you try to use 'Up arrow key ' you can get commands that are only similar to the command you are editing. But if you move your cursor to the beginning of the line you can get all the previous commands using up and down arrow keys.
-In []: legend(['sin(x)'], loc = 'center')
-
-Note that once
-other positions which can be tried are
-'best'
-'right'
-
-Very often in mathematical plots we have to define certain points and their meaning also called annotating . We next look at how to annotate
-In this case, let's add a comment at the point of origin.
-In []: annotate('local max', xy=(1.5, 1))
-
-The first argument is the comment string and second one is the position for it.
-
-As you can see, the boundary along the x-axis extends after the graph and there is an ugly blank space left on the right. Also along the y-axis, the sine plot in fact is cut by the boundary. We want to make the graph fit better. For this we shall use xlim() and ylim() to set the boundaries on the figure.
-
-In []: xlim(0, 2*pi)
-
-In []: ylim(-1.2, 1.2)
-
-The first value passed is the lower limit and the second is the upper limit. Hence when we do xlim(0, 2*pi) the boundary is set from x-value 0 to x-value 2*pi. Similarly for the y-axis.
-
-Ok, what do I do with all this effort . I obviously have to save it .
-
-We save the plot by the function savefig
-In []: savefig('sin.png') saves the figure with the name 'sin.png' in the current directory.
-
-other supported formats are: eps, ps, pdf etc.
-
-Let's see what happens when we use plot again
-In []: plot(x, cos(x)) by default plots get overlaid.
-
-we update Y axis label
-In []: ylabel('f(x)')
-
-Now in these situations with overlaid graphs, legend becomes absolutely essential. To add multiple legends, we pass the strings within quotes separated by commas and enclosed within square brackets as shown.
-
-In []: legend( [ 'sin(x)' , 'cos(x)'] )
-
-Please note that the previous legend is overwritten.
-
-In []: clf()
-clears the plot area and starts afresh.
-
-# Close the figure manually.
-
-*In case we want to create multiple plots rather than overlaid plots, we use 'figure' function.
-The figure command is used to open a plain figure window without any plot.
-In []: figure(1)
-
-We will use plot() plot again to plot a sin curve on figure(1)
-In []: plot(x, sin(x))
-
-to creates a new plain figure window without any plot type:
-In []: figure(2)
-figure() is also used to shift the focus between multiple windows.
-
-Any command issued henceforth applies to this window only so typing
-In []: plot(x, cos(x))
-plots cos curve on second window now.
-The previous plot window remains unchanged to these commands.
-
-calling function figure using argument 1 shifts the focus back to figure(1).
-In []: figure(1)
-
-title() sets the title of figure(1)
-In []: title('sin(x)')
-
-Now we save the plot of figure(1) by typing
-In []: savefig('sine.png')
-
-close() closes figure(1). Now there is just one figure that is open and hence
-the focus is automatically shifted to figure(2).
-In []: close()
-
-close() now closes the figure(2).
-In []: close()
-
-Now, what if we want to plot in a different color? The plot command can take the additional parameters such as 'g' which generates the plot in green color.
-
-What if we want a thicker line? Passing the linewidth=2 option to plot, generates the plot with linewidth of two units.
-
-In []: plot(x, sin(x), 'g', linewidth=2) and add arguments
-
-In []: clf()
-
-If we want to plot points we may pass '.' as a parameter to plot
-In []: plot(x, sin(x), '.')
-
-In []: clf()
-
-You may look at more options related to colors and type of lines using plot?(question mark)
-There are numerous options and various combinations available.
-quit the documentation using 'q'
-
-In []: clf()
-
-and finally to close the plot
-In []: close()
-
-In this tutorial we learned
-
-Some IPython Features
-Starting and exiting.
-autocompletion.
-help functionality.
-
-Regarding plotting we covered:
-How to create basic plots.
-Adding labels, legends annotation etc.
-How to change looks of the plot like colors, linewidth formats etc
-
-****************
-This brings us to the end of this tutorial. This is the first tutorial in a series of tutorials on Python for Scientific Computing. This tutorial is created by the FOSSEE team, IIT Bombay. Hope you enjoyed it and found it useful.
-****************
-
-************
-A slide of review of what has been covered and sequentially/rapidly going through them.
-************
-
-Various problems of Ipython, navigation and enter, exit.
-What about xlim and ylim?
--- a/basic-python.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-*Script
-
-
-*Hello and welcome to this tutorial on Basic Python using Python.
-
-This tutorial formally introduces Python as a language . Through this tutorial we will be able to understand Basic Data types like number , Boolean and strings .Some basic operators , simple input/output and basic conditional flow .
-
-In numbers Python supports three kinds of data types ,
-
-floats,integers and complex numbers
-
-An integer can be defined as follows :
-a=13
-
-This make a an integer variable with value 13 .
-
-You can also type 9 around 20 times
-
-a=99999999999999999999999 . as you can see Python does not have a limit on how long an integer has to be . Isn't that great .
-
-Now will try a float.
-
-let's type
-p=3.141592 if you type out p now you will notice that it is not absolutely equal to p you typed in . The reason for that is how a computer saves decimal values .
-
-Apart from integer and float, Python has an in-built support for complex numbers. Now we try to assign a complex value to a variable .
-Type:
-c = 3+4j
-As you can see ,the notation for complex numbers is similar to the one used in electric engineering.
-We will now try some operations on complex numbers . First we will try to get the absolute value of the complex number . For this we will use the abs built in function . For this do :
-abs in parenthesis c .
-
-Do get the imaginary part of c you can do :
-
-c.imag
-
-and similarly for real part do :
-
-c.real
-
-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 , this saves the value of not t that is False in f.
-
-We can apply other operators like or and and ,
-
-f or t gives us the value True while
-f and t gives us the value false.
-
-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.
-
-do
-(a and b) or c
-
-This expression gives the value True
-
-where as the expression a and (b or c) gives the value False .
-
-Now we will have a look at strings
-
-type
-w="hello"
-
-w is now a string variable with the value "hello"
-
-printing out w[0] + w[2] + w[-1] gives hlo if you notice the expression for accessing characters of a string is similar to lists .
-
-Also functions like len work with strings just like the way they did with lists
-
-Now lets try changing a character in the string in the same way we change lists .
-
-type :
-w[0]='H'
-
-oops this gives us a Type Error . Why? Because string are immutable . You can change a string simply by assigning a new element to it . This and some other features specific to string processing make string a different kind of data structure than lists .
-
-Now lets see some of the ways in which you can modify strings and other methods related to strings .
-
-Type :
-
-a = 'Hello world'
-
-To check if a particular string starts with a particular substring you can check that with startswith method
-
-a.startswith('Hell')
-
-Depending on whether the string starts with that substring the function returns true or false
-
-same is the case a.endwith('ld')
-
-a.upper()
- returns another string that is all the letters of given string capitalized
-
-similarly a.lower returns all small letters .
-
-Earlier we showed you how to see documentations of functions . You can see the documentation of the lower function by doing a.lower?
-
-You can use a.join to joing a list of strings to one string using a given string as connector .
-
-for example
-
-type :
-', '.join(['a','b','c'])
-
-In this case strings are joined over , and space
-
-Python supports formatting values into strings. Although this can include very complicated expressions, the most basic usage is to insert values into a string with the %s placeholder. %d can be used for formatting things like integers and %f for floats
-
-
-Their are many other string formatting options you can look at http://docs.python.org/library/stdtypes.html for more information on other options available for string formatting.
-
-
-Operators ---- Probably can be a different chapter .
-
-We will start the discussion on operators first with arithmetic operators .
-
-% can be used for remainder for example
-
-864675 % 10 gives remainder 5
-
-
-you can use 2 *'s for power operation
-
-for example 4 ** 3 gives the result 64
-
-One thing one should notice is the type of result depends on the types of input for example :
-
-17 / 2 both the values being integer gives the integer result 2
-
-however the result when one or two of the operators are float is float for example:
-
-17/2.0
-8.5
-17.0/2.0
-8.5
--- a/cond-loops.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,145 +0,0 @@
-* Control statements
-*** Outline
-***** Introduction
-******* What are we going to do?
-******* How are we going to do?
-******* Arsenal Required
-********* working knowledge of arrays
-
-*** Script
- Welcome.
-
- In this tutorial we shall be covering conditional statements and
- control loops. We have used them already in some of our previous
- sessions with brief introduction. We shall be covering 'if-else'
- statement, 'while' and 'for' statements formally.
-
-
- For understanding of if-else statement we will write a python
- script that takes a number as input from user and prints 0 if it is zero
- and prints "Be positive" if it is negative, prints "Single" if the input is 1
- and if the number is not 0 or 1 or negative, it prints "More".
-
- To write the program, open Scite text editor by going to Applications->
- Programming->Scite:
-
- First we prompt user for entering a integer by using raw_input
- str_x = raw_input("Enter an integer: ")
- since we know raw_input gives string, we convert the input string to an integer
- by typing
- x = int(str_x)
-
- now we check if the number is less than zero.
- type
- if x < 0:
- Please not
- #if number is negative we have to print "Be positive"
- #so we give four spaces for indentation and type
- print 'Be positive!'
-
- elif x == 0:
- to check if the number is equal to zero
- #This is else-if condition
- print 'Zero'
- elif x == 1:
- print 'Single'
- then we type the else statement which gets executed when all the if and elif statements fail
- so type
- else:
- print 'More'
-
- Save this script by going to file menu and clicking on save.
- save it in home folder with name 'ladder.py'
-
- let us check the program on ipython interpreter for various inputs
- open ipython terminal and type
- %run ladder.py
- It will prompt us to enter a integer and based on our input it
- prints appropriate message.
-
- We can use binary operators like and/or/not to check for multiple
- conditions.
-
- Python supports only if-elif-else conditional constructs,
- switch-case statements are not available/supported in Python.
-
- Now lets look at loop constructs available. Python supports 'while'
- and 'for' statements.
-
- To understand the while we shall write a script that prints all the fibonacci
- numbers less than 10. In fibonacci series the sum of previous two elements
- is equal to the next element.
-
- In Scite go to file menu and click on new and it opens a new tab.
-
- First we initialize two variable to first and second number of
- series
- a, b = 0, 1
- while b < 10:
- This block will be executed till this condition holds True
- print b,
- Note ',' here for printing values in one continues line.
- a, b = b, a+b
- This is one powerful feature of Python, swapping and assigning
- new values at the same time. After this statement a will have
- present 'b' value and b will have value of 'a+b'(phew this can be close)
-
- Save this file as 'fabonacci.py' and lets run it from IPython
- interpreter by
- %run fabonacci.py
-
- 'for' in python works any kind of iterable objects. In our
- previous sessions we used 'for' to iterate through files and lists.
-
- So we are going to use for loop print the squares of first five whole numbers.
-
- To generate squares, we have to iterate on list of numbers and we are
- going to use the range function to get the list of numbers.
-
- let us look at the documentation of range function by typing
- range?
- we see that it takes three arguments, first is the start/initial value
- second one is the stop/last value and third is the step size.
-
- Out of these, 'start' and 'step' arguments are optional.
-
- So to get list of first five natural numbers, we use
- range(5)
-
- Note here that last/stop value is not included in resulting list.
-
- So to get square of first five number all we have to do is
- iterate over this list.
- for i in range(5):
- ....print i, i*i
- ....
- ....
-
- Similarly to get square of all odd numbers from 3 to 9 we can do
- something like
-
- for i in range(3, 10, 2):
- so the list returned from range this time will start from 3 and
- end at 10(excluding it) with step size of 2 so we get odd numbers
- only
- ....print i, i*i
- ....
- ....
-
- since the for statement in python works on any iterable we can also iterate through strings
-
- to print each character in a string we do
- for c in "Guido Van Rossum":
- print c
-
- we see that it prints all the characters one by one
-
- That brings us to the end of this tutorial. We have learnt
- conditional statements in Python. How to write loops
- using 'while' statement. Range function and using for loop
-
-
- Thank you!
-
-*** Notes
-
--- a/dictionary.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-* Dictionaries
-*** Outline
-***** Dictionaries
-***** Sets
-***** Arsenal Required
-*** Script
- Welcome friends.
-
- In previous tutorial we covered Lists, Tuples and related
- functions. In this session we shall continue with Python
- data structures and cover Dictionaries and sets. We have already
- covered some basics of Dictionaries in session on Statistics. Here
- we shall revisit those concepts and some new ones.
-
- We give it a name and it returns a corresponding number.
- Dictionaries are just key-value pair. For each 'key' there is
- corresponding 'value' associated with it. In lists we use indexes
- to access elements, here we use the 'key'.
-
- Lets start by opening IPython interpreter.
- '{}' are used to create Python dictionaries. Lets create a dictionary say
-
- player = {'Mat': 134,'Inn': 233,
- 'Runs': 10823, 'Avg': 52.53}
- Let's see what player contains by typing:
-
- print player
-
- Its a dictionary storing statistics of a cricket player.
- Here 'Mat', 'Inn' etc are the keys. Now in order to get the 'average' of
- this player we simply type
- print player['Avg']
- 52.53
-
- To add a new key-value pair to this dictionary we type
- player['Name'] = 'Rahul Dravid'
- print player
- As you can see the given key-value pair has been added.
- Please note that Python dictionaries don't maintain the order
- in which the key-value pairs are stored. The order might change
- as we add new entries.
-
- In dictionaries Duplicate keys are overwritten, that is when we do
- player['Mat'] = 139
- It wont create a new entry, rather it will simply overwrite previous
- value with the new one. So
- print player
- will have updated value
-
- As we covered in one of previous sessions 'for' can be used to iterate
- through lists. The same is possible in case of dictionaries too. We can
- iterate over them using the 'keys', for example:
- for key in player:
- print key, player[key]
- This prints the keys in the dictionary along with their corresponding
- values. Notice that the order is not the same as we entered it.
-
- We saw how containership works in lists. There we can check if a
- value is present in a list or not but in case of Dictionaries we
- can only check for the containership of the keys. so
- 'Inn' in player
- returns True
- 'Econ' in Player
- returns False as there is no such 'key'
- If you try to look or search for a 'value' it will not work.
- Dictionaries support functions to retrieve keys and values
- such as
- player.keys()
- returns the list of all 'keys'
- player.values()
- return list of all 'values'
-
- Now we shall move on to 'sets'. Sets in Python are an unordered
- collection of unique elements. This data structure comes in handy in
- situations while removing duplicates from a sequence, and computing
- standard math operations on sets such as intersection, union,
- difference, and symmetric difference.
-
- Lets start by creating a set
- f10 = set([1,2,3,5,8])
- And thats how a set is created.
- f10 is the set of Fibonacci numbers less than 10
- lets print the value of f10
- print f10
-
- As we mentioned earlier, these are unordered structure so order of
- elements is not maintained, and output order is different than
- input order, just as in dictionaries. Lets create one more set, a set of
- all prime numbers less than 10
- p10 = set([2,3,5,7])
- print p10.
-
- To get union of these two sets we use the or '|' operator
- f10 | p10
-
- For intersection we use the and '&' operator:
- f10 & p10
-
- f10 - p10 gives difference between f10 and p10, that is, the set of all elements
- present in f10 but not in p10.
- The carat '^' operator gives us the symmetric difference of 2 sets. That is
- f10 union p10 minus f10 intersection p10
- f10 ^ p10
-
- To check if a set is the super set or a subset of another set, the greater than
- and the lesser than operators are used
- set([2,3]) < p10
- returns True as p10 is superset of given set
-
- Similar to lists and dictionaries, sets also supports containership so
- 2 in p10
- returns True as 2 is part of set p10 and
- 4 in p10
- returns False.
-
- The 'len' function works with sets also:
- len(f10) returns the length, which is 5 in this case.
- We can also use 'for' loops to iterate through a set just as with dictionaries and lists.
-
- With this we come to the end of this tutorial on Dictionaries and
- sets. We have seen how to initialize dictionaries, how to index them using keys
- and a few functions supported by dictionaries. We then saw how to initialize
- sets, perform various set operations and a few functions supported
- by sets. Hope you have enjoyed it, Thank you.
-
-*** Notes
--- a/functions.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-* Functions
-*** Outline
-***** Functions
-******* review of what's been done in solving equations tutorial
-********* def
-********* name
-********* arguments
-********* indented block
-********* calling a function
-******* arguments are local to a function
-******* return values
-******* doc strings - with example.
-******* code reading exercises?
-******* default arguments
-******* keyword arguments
-******* availability library functions
-*** Script
- Welcome friends.
-
- In this tutorial we shall be looking at Functions in Python. We already
- have looked at the basics of functions in the tutorial on solving
- equations. We shall first review these basics. Then we shall move on to
- other details such as doc-strings, default arguments and keyword
- arguments.
-
- First let's start IPython by typing ipython in the terminal.
-
- Let's write a simple function that prints a Hello message, upon
- accepting a name.
-
- def welcome(name):
- print "Hello", name
-
- You would recall that def is a keyword that indicates the function
- definition. 'welcome' is the name of the function and 'name' is
- the lone argument to the function. Note that the function is
- defined within an indented block, just like to any other block. Our
- function welcome just has one line in it's definition.
-
- We can call our function, as follows -
- welcome("World")
-
- (all arguments are local to a function)
-
- In general functions should be accompanied by documentation on how
- to use them. Python provides a convenient way of writing this within the
- function itself, using what are called doc strings. They were mentioned in the
- tutorial on strings. Let's look at how to write them here.
-
- Let us add a simple doc string to our welcome function.
-
- def welcome(name):
- """ Prints a hello message given a name,
- passed as argument. """
- print "Hello", name
-
- Notice that the doc string uses triple quotes. If the doc-string
- exceeds one line, we can use new line characters in it.
- Also, as expected the doc-string is indented as is required
- for anything within a block. Now that we have written the
- documentation, how do we access it? IPython provides the question
- mark feature that we have seen in the previous tutorials. welcome?
- will display the docstring that we have just written.
-
- We shall now look at default arguments.
- [show slide with examples of functions with default arguments]
- The split function has been used in two different ways in the
- given example - one for splitting on spaces and the other for
- splitting on commas.
-
- The function split is being called with no arguments and one
- argument, respectively. In the first case, white space is being
- used as a default value. Let's now edit our function, welcome, to
- use default values. (For convenience sake, we have dropped the doc-string)
-
- def welcome(name="World!"):
- print "Hello", name
-
- Now, we call the function 'welcome' without passing any arguments
- to it.
- welcome()
-
- As you can see the output is "Hello World!". Here "World!" is used as a
- default argument, when no name argument is passed to 'welcome'.
-
- Let's now look at the use of keyword arguments.
- [show slide with examples of functions with keyword arguments]
- We have already looked at functions and keyword arguments in these
- examples. loc, linewidth, xy, labels are all keywords.
-
- Let's now edit our function so that it displays a custom
- greeting message as well.
-
- def welcome( greet = 'Hello', name = 'World!'):
- print greet, name
-
- Let's now see, how we can call our updated 'welcome' function, using
- keyword arguments. We can call the function in a variety of ways.
- welcome("Hello", "James")
- welcome("Hi", name="Guido")
- welcome(name="Guido", greet="Hello")
-
- Keyword arguments allow us to call functions by passing arguments
- in any order and removes the need to remember the order of arguments
- in the function definition.
-
- Let's now write a new function
-
- def per_square(n):
- i = 1
- while ( i*i < n ):
- i += 1
- return i*i == n, i
-
- What does this function do? It checks if the given number is a perfect square.
- If it is, then the function returns True along with the square root of
- the given number. If the number is not a perfect square it returns
- False and the square root of the next perfect square.
-
- Please observe that this function returns 2 values.
- In Python there is no restriction on the number of values returned by
- a function. Whenever a function has to return more than one value, the multiple
- values are packed into one single tuple and that single tuple is returned.
-
- With this we come to the end of this tutorial on functions. In this tutorial
- we have learnt about functions in a greater detail. We looked at
- how to define functions, calling them, default and keyword
- arguments.
-
-*** Notes
--- a/functions_.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-While we have talked about how you can do simple tasks in Python we haven't started to talk about how you can organize your code . One of the first techniques we use to break a task into relatively independent subtask . These can share data with other parts of the program . These code blocks clubbed together are called functions or subroutines .
-
-def keyword in Python is used to define a function.
-Arguments are local to a function , i.e you can access the arguments only in a particular function in other places it shall raise a Name error .
-
-One of the great things about python is that a function can return multiple values . Essentialy it does it by packing the multiple values in a tuple .
-
-Lets look at how to write functions by writing one out .
-
-We have given the function the name signum . Essentially what it does is that based on whether the no is 0 , negative or positive , it returns 0 , -1 and +1 respectively . In this case it recieves value of the no in variable r .
-
-In the beginning of the function you can see a triple quoted string . This is called a docstring. You can write some documentation related to your function. In this you can have the function parameters and what it returns. A python function returns a value by using the keyword return.
-
--- a/ipython-tut.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-Hello friends and welcome to this tutorial on IPython and its features. IPython
-is an enhanced interactive Python interpreter. IPython provides various advanced
-features that the vanilla Python interpreter does not. We have seen some of these
-features in the previous tutorials. In this tutorial we shall recall them and
-look at a few more new ones.
-
-
-
-
--- a/least-squares.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-* Least Squares Fit
-*** Outline
-***** Introduction
-******* What do we want to do? Why?
-********* What's a least square fit?
-********* Why is it useful?
-******* How are we doing it?
-******* Arsenal Required
-********* working knowledge of arrays
-********* plotting
-********* file reading
-***** Procedure
-******* The equation (for a single point)
-******* It's matrix form
-******* Getting the required matrices
-******* getting the solution
-******* plotting
-*** Script
- Welcome.
-
- In this tutorial we shall look at obtaining the least squares fit
- of a given data-set. For this purpose, we shall use the same
- pendulum data that we used in the tutorial on plotting from files.
-
- To be able to follow this tutorial comfortably, you should have a
- working knowledge of arrays, plotting and file reading.
-
- A least squares fit curve is the curve for which the sum of the
- squares of it's distance from the given set of points is
- minimum.
-
- Previously, when we plotted the data from pendulum.txt we got a
- scatter plot of points as shown.
-
- In our example, we know that the length of the pendulum is
- proportional to the square of the time-period. But when we plot
- the data using lines we get a distorted line as shown. What
- we expect ideally, is something like the redline in this graph.
- From the problem we know that L is directly proportional to T^2.
- But experimental data invariably contains errors and hence does
- not produce an ideal plot. The best fit curve for this data has
- to be a linear curve and this can be obtained by performing least
- square fit on the data set. We shall use the lstsq function to
- obtain the least squares fit curve.
-
- The equation of the line is of the form T^2 = mL+c. We have a set
- of values for L and the corresponding T^2 values. Using this, we
- wish to obtain the equation of the straight line.
-
- In matrix form the equation is represented as shown,
- Tsq = A.p where Tsq is an NX1 matrix, and A is an NX2 matrix as shown.
- And p is a 2X1 matrix of the slope and Y-intercept. In order to
- obtain the least square fit curve we need to find the matrix p
-
- Let's get started. As you can see, the file pendulum.txt
- is on our Desktop and hence we navigate to the Desktop by typing
- cd Desktop. Let's now fire up IPython: ipython -pylab
-
- We have already seen (in a previous tutorial), how to read a file
- and obtain the data set using loadtxt(). Let's quickly get the required data
- from our file.
-
- l, t = loadtxt('pendulum.txt', unpack=True)
-
- loadtxt() directly stores the values in the pendulum.txt into arrays l and t
- Let's now calculate the values of square of the time-period.
-
- tsq = t*t
-
- Now we shall obtain A, in the desired form using some simple array
- manipulation
-
- A = array([l, ones_like(l)])
-
- As we have seen in a previous tutorial, ones_like() gives an array similar
- in shape to the given array, in this case l, with all the elements as 1.
- Please note, this is how we create an array from an existing array.
-
- Let's now look at the shape of A.
- A.shape
- This is an 2X90 matrix. But we need a 90X2 matrix, so we shall transpose it.
-
- A = A.T
-
- Type A, to confirm that we have obtained the desired array.
- A
- Also note the shape of A.
- A.shape
-
- We shall now use the lstsq function, to obtain the coefficients m
- and c. lstsq returns a lot of things along with these
- coefficients. We may look at the documentation of lstsq, for more
- information by typing lstsq?
- result = lstsq(A,tsq)
-
- We extract the required coefficients, which is the first element
- in the list of things that lstsq returns, and store them into the variable coef.
- coef = result[0]
-
- To obtain the plot of the line, we simply use the equation of the
- line, we have noted before. T^2 = mL + c.
-
- Tline = coef[0]*l + coef[1]
- plot(l, Tline, 'r')
-
- Also, it would be nice to have a plot of the points. So,
- plot(l, tsq, 'o')
-
- This brings us to the end of this tutorial. In this tutorial,
- you've learnt how to obtain a least squares fit curve for a given
- set of points using lstsq. There are other curve fitting functions
- available in Pylab such as polyfit.
-
- Hope you enjoyed it. Thanks.
-
-*** Notes
-
--- a/lists.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,141 +0,0 @@
-* Lists
-*** Outline
-***** Lists
-***** Tuples
-***** Arsenal Required
-*** Script
- Welcome friends.
-
- In this tutorial we shall look at some special Data structures
- supported by Python namely Lists and Tuples. We have already been
- introduced to lists in some of the previous tutorials, here we
- shall look at them in little more detail.
-
- The list type is a container that holds a number of other
- objects, in the given order. Lists allow you to add and
- remove objects from the sequence.
-
- First lets start the interpreter by typing ipython in terminal.
- We create our first list by typing
- num = [1, 2, 3, 4]
- Items enclosed in square brackets separated by comma
- constitutes a list.
- One neat feature of Python list is that we can store data of any
- type in them. We can have a list something like:
- var = [1, 1.2, 'string']
- print var
-
- Similar to strings, we can concatenate two lists using '+'
- operator
- so num + var will return a new list with the contents of both
- 'num' and 'var' one after the other.
- Let's look at what num contains now
- print num
- As you can see num is unchanged by the '+' operator.
-
- We have already covered the append function in one of our previous
- tutorials.
- To add single object at the end of a list the 'append'
- function is used
- Let's now append -5 to it.
- num.append(-5)
- The contents of num have been changed now.
- print num
- append takes only one argument. And append behaves different
- from + operator. While + returns a new list with two lists
- added, append will simply add the entire object to the
- end of the list:
- num.append([9, 10, 11])
- print num
- It adds the entire list as one element and not separate elements.
- In order to add separate elements we use the 'extend' function
- Let's reinitialize num
- num = [1, 4, -6]
- num.extend([2, 8, 0])
- print num
-
- Let's now move on to see more functions available
- with lists.
- To reverse a list, we have the 'reverse' function.
- Please note the order of the elements in num. Let's now do:
- num.reverse()
- Now after using reverse function, lets check the value of 'num'
- print num
- Please note, the reverse() function actually manipulated the list.
- To remove a particular element from the list Python provides
- the remove() function
- num.remove(8)
- if the given argument is present more than once in the list,
- then the first occurrence of that element is removed from list.
-
- The Slicing and Striding concepts which we covered for Arrays work
- with lists as well. Lets revisit the concept by looking at some examples
- a = [1, 2, 3, 4, 5]
- print a[1:3] returns a list with second and third element of 'a'
- One important feature of list indexing is the negative index. In
- Lists -1 indicates last element of the list
- print a[-1]
- similarly -2 will be second last and so forth. Now these
- negative indexes can also be used with slicing. If we try
- print a[1:-1]
- we get list which excludes first and last element of a.
- and if we do not specify the start or the end index value the default
- values are taken. The default values being the first element and the
- last element.
- print a[:3] will return a list from beginning upto the fourth element of a.
- We can perform striding as well, by specifying the step size
- print a[1:-1:2]
- This gives second, fourth and so on items of a till we reach
- last item of list.
- print a[::2] will skip all the even placed elements of a
- With step sizes, if we specify negative values we get some
- interesting results. Lets try
- print a[4:1:-1]
- Here we begin at the 5th element and go upto the 2nd element in the
- reverse order since step size is -1
- print a[::-1]
- This returns a slice with all the elements in 'a' reversed in order.
- Here the negative step indicates that the start point has to be the
- last element and the end point has to be the first element and the order
- has to be reversed.
-
- Let's now move on to other functionality
- We can check for containership of elements within lists as well.
- Let's look at the contents of num
- print num
- To check if the number 4 is present in the list we type
- 4 in num
- True
-
- Now let's move onto Tuples.
- Python provides support for special immutable lists known as
- 'tuple' To create a tuple instead we use normal brackets '('
- unlike '[' for lists.
- t = (1, 2, 3, 4, 5, 6, 7, 8)
- its elements can also be accessed using indexes just like lists.
- print t[0] + t[3] + t[-1]
- but operation like
- t[4] = 7 are not allowed
- These features of tuples have their advantages. To see where
- are they used we first create two variables
- a, b = 1, 6
- print a, b
- As you can see multiple variable assignments are possible using
- tuples.
- Now lets swap values their values. Normal approach would be
- to create a temporary to hold the value but because of tuples
- we can do something cool like
- b, a = a, b
- print a, b
- and values are swapped. And this swapping works for all types
- of variables. This is possible because of something magical
- that Python does called as tuple packing and unpacking.
-
- With this we come to the end of this tutorial on Lists and
- tuples. In this tutorial we have learnt about initializing,
- various list operations, slicing and striding. We learnt
- about tuple initialization, packing and unpacking. In next
- session we will cover more on Python supported data
- structures. Thank you!
-
-*** Notes
--- a/loopsdatastruct.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-(Next slide)
-
-
-Lists
-~~~~~
-
--- a/matrices.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-* Matrices
-*** Outline
-***** Introduction
-******* Why do we want to do that?
-******* We shall use arrays (introduced before) for matrices
-******* Arsenal Required
-********* working knowledge of arrays
-***** Various matrix operations
-******* Transpose
-******* Sum of all elements
-******* Element wise operations
-******* Matrix multiplication
-******* Inverse of a matrix
-******* Determinant
-******* eigen values/vectors
-******* svd
-***** Other things available?
-*** Script
- Welcome.
-
- In this tutorial, you will learn how to perform some common matrix
- operations. We shall look at some of the functions available in
- pylab. Note that, this tutorial just scratches the surface and
- there is a lot more that can be done.
-
- Let's begin with finding the transpose of a matrix.
-
- In []: a = array([[ 1, 1, 2, -1],
- ...: [ 2, 5, -1, -9],
- ...: [ 2, 1, -1, 3],
- ...: [ 1, -3, 2, 7]])
-
- In []: a.T
-
- Type a, to observe the change in a.
- In []: a
-
- Now we shall look at adding another matrix b, to a. It doesn't
- require anything special, just use the + operator.
-
- In []: b = array([[3, 2, -1, 5],
- [2, -2, 4, 9],
- [-1, 0.5, -1, -7],
- [9, -5, 7, 3]])
- In []: a + b
-
- What do you expect would be the result, if we used * instead of
- the + operator?
-
- In []: a*b
-
- You get an element-wise product of the two arrays and not a matrix
- product. To get a matrix product, we use the dot function.
-
- In []: dot(a, b)
-
- The sum function returns the sum of all the elements of the
- array.
-
- In []: sum(a)
-
- The inv command returns the inverse of the matrix.
- In []: inv(a)
-
- In []: det(a)
-
- In []: eig(a)
- Returns the eigenvalues and the eigen vectors.
-
- In []: eigvals(a)
- Returns only the eigenvalues.
-
- In []: svd(a)
- Singular Value Decomposition
-
-*** Notes
-
--- a/numbers.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-* Data Types
-*** Outline
-***** Introduction
-******* What are we going to do?
-******* How are we going to do?
-******* Arsenal Required
-********* None
-*** Script
- Welcome friends.
-
- This session is about numbers and mathematical operations
-
- In this tutorial we shall be covering data types, operators and
- type conversion.
- To represent 'Numbers' in python, we have int, float, complex
- datatypes
- For conditional statements, we have 'Bool' datatype
-
- type ipython on terminal to start the interpreter.
- Lets start with 'numbers'
- Now we will create a variable, say
- x = 13 lets confirm the value of x by
- print x
-
- To check the data type of any variable Python provides 'type' function
- type(x)
- which tells us that the x is of type 'int'
-
- lets create one more variable
- y = 999999999999
- print y
-
- Python can store any integer however big it is.
-
- Floating point numbers come under 'float' datatype
- p = 3.141592
- type(p)
-
- Python by default provides support for complex numbers also.
- c = 3+4j
- creates a complex number c with real part 3 and imaginary part 4.
- Please note that here 'j' is used to specify the imaginary
- part and not i.
- type(c)
- Python also provides basic functions for their manipulations like
- abs(c) will return the absolute value of c.
- c.imag returns imaginary part and c.real gives the real part.
-
- All the basic operators work with Python data types, without any
- surprises. When we try to add two numbers like x and y Python takes
- cares of returning 'right' answer
-
- print x + y gives sum of x and y
-
- Same as additions multiplication also works just right:
- 123 * 4567
- gives you the product of both numbers
-
- Integer division in Python truncates, which means, when we divide an integer
- with another integer result is also integer and decimal
- value is truncated. So
- 17 / 2 returns 8 and not 8.5
-
- but int and float value operations like
- 17 / 2.0 will return the correct 8.5, similarly
- 17.0 / 2 will also give correct answer.
-
- in python x ** y returns x raised to power y. For example lets try:
- 2 ** 3 and we get 2 raised to power 3 which is 8
-
- now lets try power operation involving a big number
- big = 1234567891234567890 ** 3
- As we know, any number irrespective of its size can be represented in python.
- hence big is a really big number and print big prints the value of big.
-
- % operator is for modulo operations
- 1786 % 12 gives 10
- 45 % 2 returns 1
-
- Other operators which comes handy are:
- +=
- lets create one variable a with
- a = 7546
- now
- a += 1 will increment the value of 'a' by 1
- similarly
- a -= 1 will decrement.
- we can also use
- a *= a
- a
- a is multiplied by itself.
-
- a /= 5
- a is divided by 5
-
- Next we will look at Boolean datatype:
- Its a primitive datatype having one of two values: True or False.
- t = True
- print t
-
- Python is case sensitive language, so True with 'T' is boolean type but
- true with 't' would be a variable.
-
- f = not True
-
- we can do binary operations like 'or', 'and', 'not' with these variables
- f or t is false or true and hence we get true
- f and t is flase and true which gives false
-
- in case of multiple binary operations to make sure of precedence use
- 'parenthesis ()'
- a = False
- b = True
- c = True
- if we need the result of a and b orred with c, we do
- (a and b) or c
- first a and b is evaluated and then the result is orred with c
- we get True
- but if we do
- a and (b or c)
- there is a change in precedence and we get False
-
- Python also has support for relational and logical operators. Lets try some
- examples:
- We start with initializing three variables by typing
- p, z, n = 1, 0, -1
- To check equivalency of two variables use '=='
- p == z checks if 1 is equal to 0 which is False
- p >= n checks if 1 is greater than or equal to -1 which is True
-
- We can also check for multiple logical operations in one statement itself.
- n < z < p gives True.
- This statement checks if 'z' is smaller than 'p' and greater than 'n'
-
- For inequality testing we use '!'
- p + n != z will add 'p' and 'n' and check the equivalence with z
-
- We have already covered conversion between datatypes in some of the previous sessions, briefly.
-
- Lets look at converting one data type to another
- lets create a float by typing z = 8.5
- and convert it to int using
- i = int(z)
- lets see what is in i by typing print i
- and we get 8
- we can even check the datatype of i by typing type(i)
- and we get int
-
- similarly float(5) gives 5.0 which is a float
-
- type float_a = 2.0 and int_a = 2
- 17 / float_a gives 8.5
- and int( 17 / float_a ) gives you 8 since int function truncates the decimal value of the result
-
-
- float(17 / int_a ) we get 8.0 and not 8.5 since 17/2 is already truncated to 8
- and converting that to float wont restore the lost decimal digits.
-
- To get correct answer from such division try
- 17 / float(a)
-
- To round off a float to a given precision 'round' function can be
- used.
- round(7.5) returns 8.
-
- This brings us to the end of tutorial on introduction to Data types
- related to numbers in Python. In this tutorial we have learnt what are
- supported data types for numbers, operations and operators and how to
- convert one data type to other.
-
- Hope you have enjoyed the tutorial and found it useful.Thank you!
-
-*** Notes
--- a/odes.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-* Solving ODEs
-*** Outline
-***** Introduction
-******* What are we going to do?
-******* How are we going to do?
-******* Arsenal Required
-********* working knowledge of arrays
-********* working knowledge of functions
-*** Script
- Welcome friends.
-
- In this tutorial we shall look at solving Ordinary Differential Equations,
- ODE henceforth using odeint in Python. In this tutorial we shall be using
- the concepts of arrays, functions and lists which we have covered in
- previous tutorials.
-
- Let's consider the classic problem of the spread of an epidemic in a
- population.
- This is given by the ordinary differential equation dy/dt = ky(L-y)
- where L is the total population and k is an arbitrary constant. For our
- problem Let us use L=250000, k=0.00003.
- Let the boundary condition be y(0)=250.
-
- Let's now fire up IPython by typing ipython -pylab interpreter.
-
- As we saw in one of the earlier sessions, sometimes we will need more than
- pylab to get our job done. For solving 'ordinary differential equations'
- we shall have to import 'odeint' function, which is a part of the SciPy package.
- So we run the magic command:
-
- In []: from scipy.integrate import odeint
-
- The details regarding `import' shall be covered in a subsequent tutorial.
-
- We can represent the given ODE as a Python function.
- This function takes the dependent variable y and the independent variable t
- as arguments and returns the ODE.
-
- Let us now define our function.
-
- In []: def epid(y, t):
- .... k = 0.00003
- .... L = 250000
- .... return k*y*(L-y)
-
- Independent variable t can be assigned the values in the interval of
- 0 and 12 with 61 points using linspace:
-
- In []: t = linspace(0, 12, 61)
-
- Now obtaining the solution of the ode we defined, is as simple as
- calling the Python's odeint function which we just imported:
-
- In []: y = odeint(epid, 250, t)
-
- We can plot the the values of y against t to get a graphical picture our ODE.
-
- plot(y, t)
- Lets now close this plot and move on to solving ordinary differential equation of
- second order.
- Here we shall take the example ODEs of a simple pendulum.
-
- The equations can be written as a system of two first order ODEs
-
- d(theta)/dt = omega
-
- and
-
- d(omega)/dt = - g/L sin(theta)
-
- Let us define the boundary conditions as: at t = 0,
- theta = theta naught = 10 degrees and
- omega = 0
-
- Let us first define our system of equations as a Python function, pend_int.
- As in the earlier case of single ODE we shall use odeint function of Python
- to solve this system of equations by passing pend_int to odeint.
-
- pend_int is defined as shown:
-
- In []: def pend_int(initial, t):
- .... theta = initial[0]
- .... omega = initial[1]
- .... g = 9.81
- .... L = 0.2
- .... f=[omega, -(g/L)*sin(theta)]
- .... return f
- ....
-
- It takes two arguments. The first argument itself containing two
- dependent variables in the system, theta and omega.
- The second argument is the independent variable t.
-
- In the function we assign the first and second values of the
- initial argument to theta and omega respectively.
- Acceleration due to gravity, as we know is 9.81 meter per second sqaure.
- Let the length of the the pendulum be 0.2 meter.
-
- We create a list, f, of two equations which corresponds to our two ODEs,
- that is d(theta)/dt = omega and d(omega)/dt = - g/L sin(theta).
- We return this list of equations f.
-
- Now we can create a set of values for our time variable t over which we need
- to integrate our system of ODEs. Let us say,
-
- In []: t = linspace(0, 20, 101)
-
- We shall assign the boundary conditions to the variable initial.
-
- In []: initial = [10*2*pi/360, 0]
-
- Now solving this system is just a matter of calling the odeint function with
- the correct arguments.
-
- In []: pend_sol = odeint(pend_int, initial,t)
-
- In []: plot(pend_sol)
- This gives us 2 plots. The green plot is omega vs t and the blue is theta vs t.
-
- Thus we come to the end of this tutorial. In this tutorial we have learnt how to solve ordinary
- differential equations of first and second order.
-
-*** Notes
--- a/plotting-files.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-* Plotting Experimental Data
-*** Outline
-***** Introduction
-******* Why do we want to do that?
-******* Inputting data
-********* Lists
-********* Files
-******* Arsenal Required
-********* Lists
-*********** initializing
-*********** appending to lists
-********* for loops
-*********** iterating over a list
-********* basic plotting
-***** Inputting data as lists
-******* Input the dependent and independent variables in two lists
-******* Plot the points
-***** Plotting from files
-******* Look at the file
-******* Read the file and get data into variables
-******* Do any massaging required
-******* Plot the points
-
-*** Script
-
-This video will teach you how to plot experimental data, with two
-variables.
-
-In general, we don't plot (analytical) functions. We often have
-experimental data points, that we wish to plot. We shall look at
-inputting this data and plotting it.
-
-The data could be input (or entered) in two formats. For smaller data
-sets we could use lists to input the data and use plain text files for
-(somewhat?) larger ones. (Binary files?)
-
-[[[Before starting with this video, you should be comfortable with
- - Lists
- - initializing them
- - appending elements to lists
- - for command
- - iterating over a list
- - split command
- - plot command
- - plotting two variables
-]]]
-
-Let's begin with inputting the data as lists and plotting it.
-
-x = [0, 1, 2.1, 3.1, 4.2, 5.2]
-y = [0, 0.8, 0.9, 0, -0.9, -0.8]
-Now we have two lists x and y, with the values that we wish to plot.
-
-We say:
-plot (x, y, 'o')
-
-and there, we have our plot!
-
-[We close the plot window. ]
-
-Now, that we know how to plot data which is in lists, we will look at
-plotting data which is in a text file. Essentially, we read the data
-from the file and massage it into lists again. Then we can easily
-plot it, as we already did.
-
-As an example we will use the data collected from a simple pendulum
-experiment. We have the data of, the length of pendulum vs. the time
-period of the pendulum in the file pendulum.txt
-
-In []: cat pendulum.txt (windows?)
-
-The cat command, shows the contents of the file.
-
-The first column is the length of the pendulum and the second column
-is the time. We read the file line-by-line, collect the data into
-lists and plot them.
-
-We begin with initializing three empty lists for length, time-period
-and square of the time-period.
-
-l = []
-t = []
-tsq = []
-
-Now we open the file and read it line by line.
-for line in open('pendulum.txt'):
-
-We split each line at the space
- point = line.split()
-
-Then we append the length and time values to the corresponding
-lists. Note that they are converted from strings to floats, before
-appending to the lists
- l.append(float(point[0])
- t.append(float(point[1])
-We also calculate the squares of the time-period and append to the end
-of the tsq list.
- tsq.append(t[-1]*t[-1])
-As you might be aware, t[-1] gives the last element of the list t.
-
-Now the lists l, t have the required data. We can simply plot them, as
-we did already.
-
-plot(l, t, 'o')
-
-Enjoy!
-
-*** Notes
- - Also put in code snippets?
--- a/plotting-files.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-**********************************************************************************
-Hello and welcome, this is the second tutorial in the series of spoken tutorials on Python for Scientific computing.
-
-Here we will teach you how to plot experimental data.
-
-You can input the data either as a list or read from a plain text/binary file. We will cover both one by one.
-Please make sure you have pendulum.txt file, as mentioned on requirement list of session
-
-So let's begin. First we will input the data as lists and then we will plot it.
-So on the Interpreter we will type
-x = [0, 1, 2.1, 3.1, 4.2, 5.2]
-here x is a list. In python, list is a container that holds a number of objects. Various functions related to lists will be covered in more detail later.
-
-Now for the corresponding Y values type
-y = [0, 0.8, 0.9, 0, -0.9, -0.8]
-
-Now we have x and y in two separate lists and we plot x vs. y via:
-plot (x, y, 'o')
-
-Here, we have our plot!
-[We close the plot window. ]
-
-Now, that we know how to plot data from lists, we will look at plotting data from a text file. Essentially, we read the data from the file and fit them into lists again. Then we can easily plot it, as we did before.
-
-As an example we will use the data collected from a simple pendulum experiment.
-
-In []: cat pendulum.txt (windows wont work!)
-The cat command shows the file content.
-The first column is the length of the pendulum and the second column is the time. We read the file line-by-line, collect the data into lists and plot them.
-
-We begin with initializing three empty lists for length, time-period and square of the time-period.
-l = []
-t = []
-tsq = []
-
-Now we open the file and read it line by line.
-for line in open('pendulum.txt'):
-
-The ':' at the end of the 'for' statement marks the start of the block.
-'open' returns an iterable object which we traverse using the 'for' loop. In python, 'for' iterates over items of any sequence.
-#we will cover more about the 'for' loop in other spoken tutorials
-'line' is a string variable storing one line at a time as the 'for' loop iterates through the file.
-
-We split each line at the space using
- point = line.split()
-split function will return a list. In this case it will have two elements, first is length and second is time.
-
-Note the indentation here. Everything inside the 'for' loop has to be indented by 4 spaces.
-Then we append the length and time values to the corresponding lists. Note that they are converted from strings to floats, before appending to the lists
- l.append(float(point[0]))
-append is a function used to append one element to the list.
- t.append(float(point[1]))
-
-By now we have the time and length values in two lists. Now to get the square of the time values, we will write one more 'for' loop which will iterate through list 't'
-
-for time in t:
- tsq.append(time*time)
-
-Now lists l(en) and tsq have the required data. We can simply plot them, as we did earlier.
-plot(l, tsq, 'o')
-
-So here is the required plot. In this way, you can plot data from files. Hope this information was helpful. See you in the next tutorial
-
-******************
-
-For alternate ways of loading data from files go through the tutorial on loadtxt
-We should have two tutorials here, one should be basic, using for loops and lists
-Second one using loadtxt.
--- a/plotting-script.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-**********************************************************************************
-Hello friends and welcome to the second tutorial in the series of spoken tutorials on Python for Scientific computing.
-
-In the previous tutorial we learnt how to obtain basic plots using a set of points.
-We plot experimental data more often that we plot mathematical curves.
-So here we shall learn how to plot experimental data.
-
-You can input the data either as a list or read from a plain text/binary file. We shall cover both one by one.
-Please make sure you have pendulum.txt file, as mentioned on requirement list of the session.
-As you can see the pendulum.txt file in our case is on the desktop and we are currently in the home directory.
-So we navigate to the desktop, using cd Desktop. Now let's start IPython by typing ipython -pylab.
-
-First we shall look into using lists to input the data and then we shall plot it.
-Type
-x = open square bracket 0, 1, 2.1, 3.1, 4.2, 5.2 close square bracket.
-here x is a list. In python, list is a container that holds a number of objects in the given order.
-We shall look into other functions related to lists a little later.
-
-Now for the corresponding Y values type
-y = open square bracket 0, 0.8, 0.9, 0, -0.9, -0.8 close square bracket.
-
-Now that we have x and y in two separate lists and we plot x vs. y using
-plot (x, y, 'o') The o within quotes plots with filled circles. And lo! We have our plot!
-
-
-[We close the plot window. ]
-
-Now, that we know how to plot data from lists, we will look at plotting data from a text file. Essentially, if we read the data from the file and fit them into lists, we can easily plot the data, just as we did previously.
-
-Here we shall use the data collected from a simple pendulum experiment as an example. The aim of the experiment is to plot the length versus square of the time period.
-Let us check out what pendulum.txt contains. Type cat pendulum.txt
-
-Windows users just double click on the file to open it. Please be careful not to edit the file.
-
-The first column is the length of the pendulum and the second column is the time period. We read the file line-by-line, collect the data into lists and plot them.
-
-Let's begin with initializing three empty lists for length, time-period and square of the time-period.
-l = []
-t = []
-tsq = []
-
-Initializing an empty list is done as shown above using just a pair of square brackets without any content in them.
-
-Now we open the file and read it line by line.
-for line in open (within quotes the file name. )('pendulum.txt'):
-
-The ':' at the end of the 'for' statement marks the beginning of the for block.
-'open' returns an iterable object which we traverse using the 'for' loop. In python, 'for' iterates over items of a sequence.
-For more details regarding the for loop refer to our tutorial on loops and data structures.
-Whatever we read from a file is in the form of strings. Thus 'line' here is a string variable that contains one line of the file at a time as the 'for' loop iterates through the file.
-
-We split each line at the space using
- point = line.split()
-the split function returns a list of elements from the 'line' variable split over spaces. In this case it will have two elements, first is length and second is time. point here contains 2 elements, the first one is the length and the second one is the time period
-
-Note the indentation here. Everything inside the 'for' loop has to be indented by 4 spaces.
-Then we append the length and time values to the appropriate lists. Since we cannot perform mathematical operations on strings, we need to convert the strings to floats, before appending to the lists.
- l.append(float(point[0]))
-append is a function used to append a single element to a list.
- t.append(float(point[1]))
-
-That's it, now we need to exit the loop. Hit the enter key twice.
-
-Now we have the time and length values in two lists. Now to get the square of the time values, we shall write one more 'for' loop which will iterate through list 't'
-
-for time in t:
- tsq.append(time*time)
-
-Let us now verify if l, t and tsq have the same number of elements. Type
-print len(l), len(t), len(tsq)
-
-Now we have verified that all three have the same dimensions. lists l and tsq have the required data. Let's now plot them, as we did earlier.
-plot(l, tsq, 'o')
-
-So here is the required plot. We may proceed to label the axes, title the plot and save it.
-
-In this tutorial we have learnt how to create lists and append items to them. We have learnt how to process data using lists, how to open and read files and the 'for' loop.
-
-That brings us to the end of this session.
-Hope this information was helpful. Thank you.
--- a/presentations/arrays.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Matrices}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- \begin{itemize}
- \item Perform efficient matrix operations.
- \item Basic Image processing.
- \end{itemize}
- \end{block}
- \begin{block}{Checklist}
- \begin{itemize}
- \item lena.png
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Matrix operations using arrays}
- Matrices using arrays:
- \begin{itemize}
- \item Creating and initializing arrays
- \item Manipulating arrays
- \item Using arrays to solve problems
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{Matrices}
- \begin{itemize}
- \item Creating and initializing arrays
- \item Manipulating arrays
- \item Basic Image processing using arrays
- \item Performing Matrix operations using arrays
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/basic-plot.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-%%% This is from Fernando's setup.
-% \usepackage{color}
-% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
-% % Use and configure listings package for nicely formatted code
-% \usepackage{listings}
-% \lstset{
-% language=Python,
-% basicstyle=\small\ttfamily,
-% commentstyle=\ttfamily\color{blue},
-% stringstyle=\ttfamily\color{orange},
-% showstringspaces=false,
-% breaklines=true,
-% postbreak = \space\dots
-% }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Title page
-\title[Basic Plotting]{Python for Scientific Computing : Basic Plotting}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Intended Audience}
- \begin{itemize}
- \item Engg., Mathematics and Science teachers.
- \item Interested students from similar streams.
- \end{itemize}
- \end{block}
-
- \begin{block}{Goal: Successful participants will be able to}
- \begin{itemize}
- \item Use Python as a basic Plotting tool.
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
-\frametitle{Checklist}
- \begin{itemize}
- \item IPython
- \item Pylab
- \end{itemize}
-\end{frame}
-
-%% \begin{frame}[fragile]
-%% \frametitle{Starting up \ldots}
-%% \begin{block}{}
-%% \begin{verbatim}
-%% $ ipython -pylab
-%% \end{verbatim}
-%% \end{block}
-%% \begin{lstlisting}
-%% In []: print "Hello, World!"
-%% Hello, World!
-%% \end{lstlisting}
-%% Exiting
-%% \begin{lstlisting}
-%% In []: ^D(Ctrl-D)
-%% Do you really want to exit([y]/n)? y
-%% \end{lstlisting}
-%% \end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{IPython}
- \begin{itemize}
- \item Starting and Quiting.
- \item AutoCompletion
- \item Help
- \end{itemize}
- \end{block}
- \begin{block}{Plotting}
- \begin{itemize}
- \item Creating simple plots.
- \item Adding labels and legends.
- \item Annotating plots.
- \item Changing the looks: size, linewidth, colors
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This is first tutorial from the series of
- \begin{center}
- \textcolor{blue}{'Python for Scientific Computing'}.
- \end{center}
- \end{block}
- \begin{block}{}
- It is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
-
Binary file presentations/data/L-TSq-limited.png has changed
Binary file presentations/data/L-Tsq-Line.png has changed
Binary file presentations/data/L-Tsq-points.png has changed
Binary file presentations/data/L-Tsq.png has changed
Binary file presentations/data/all_regions.png has changed
Binary file presentations/data/annotate.png has changed
Binary file presentations/data/dash.png has changed
Binary file presentations/data/filter.png has changed
Binary file presentations/data/firstplot.png has changed
Binary file presentations/data/fwdDiff.png has changed
Binary file presentations/data/green.png has changed
Binary file presentations/data/interpolate.png has changed
Binary file presentations/data/label.png has changed
Binary file presentations/data/least-sq-fit.png has changed
Binary file presentations/data/legend.png has changed
Binary file presentations/data/lena.png has changed
Binary file presentations/data/loc.png has changed
Binary file presentations/data/missing_points.png has changed
--- a/presentations/data/pendulum.txt Mon Sep 13 18:35:56 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
Binary file presentations/data/plot1.png has changed
Binary file presentations/data/plot10.png has changed
Binary file presentations/data/plot11.png has changed
Binary file presentations/data/plot2.png has changed
Binary file presentations/data/plot3.png has changed
Binary file presentations/data/plot4.png has changed
Binary file presentations/data/plot5.png has changed
Binary file presentations/data/plot6.png has changed
Binary file presentations/data/plot7.png has changed
Binary file presentations/data/plot8.png has changed
Binary file presentations/data/plot9.png has changed
--- a/presentations/data/points.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-0.01 153.990844267
-0.06 156.161844972
-0.11 158.226964724
-0.16 160.191367397
-0.21 162.059965021
-0.26 163.837430063
-0.31 165.528207113
-0.36 167.136523992
-0.41 168.666402332
-0.46 170.121667625
-0.51 171.505958792
-0.56 172.822737282
-0.61 174.075295727
-0.66 175.266766176
-0.71 176.400127926
-1.26 185.75176924
-1.31 186.373771356
-1.36 186.965438071
-1.41 187.52824886
-1.46 188.063611042
-1.51 187.533026401
-1.56 177.900088899
-1.61 168.736955303
-1.66 160.020713006
-1.71 151.729566862
-1.76 143.842784687
-1.81 136.340645417
-1.86 129.204389797
-1.91 122.416173471
-1.96 115.959022361
-2.51 62.67951023
-2.56 59.135750565
-2.61 55.7648220983
-2.66 52.5582957529
-2.71 49.5081535427
-2.76 46.6067685235
-2.81 43.8468857214
-2.86 41.2216039918
-2.91 38.7243587631
-2.96 36.3489056213
--- a/presentations/data/pos.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-0. 0.
-0.25 0.47775
-0.5 0.931
-0.75 1.35975
-1. 1.764
-1.25 2.14375
-1.5 2.499
-1.75 2.82975
-2. 3.136
-2.25 3.41775
-2.5 3.675
-2.75 3.90775
-3. 4.116
-3.25 4.29975
-3.5 4.459
-3.75 4.59375
-4. 4.704
-4.25 4.78975
-4.5 4.851
-4.75 4.88775
-5. 4.9
-5.25 4.88775
-5.5 4.851
-5.75 4.78975
-6. 4.704
-6.25 4.59375
-6.5 4.459
-6.75 4.29975
-7. 4.116
-7.25 3.90775
-7.5 3.675
-7.75 3.41775
-8. 3.136
-8.25 2.82975
-8.5 2.499
-8.75 2.14375
-9. 1.764
-9.25 1.35975
-9.5 0.931
-9.75 0.47775
-10. 0.
Binary file presentations/data/pos_vel_accel.png has changed
Binary file presentations/data/position.png has changed
Binary file presentations/data/science.png has changed
Binary file presentations/data/smoothing.gif has changed
Binary file presentations/data/stline_dots.png has changed
Binary file presentations/data/stline_points.png has changed
Binary file presentations/data/straightline.png has changed
Binary file presentations/data/title.png has changed
--- a/presentations/functions.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Functions}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \titlepage
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Functions in Python}
- \begin{itemize}
- \item Function definition
- \item Function call
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Functions: default arguments}
- \begin{lstlisting}
-In []: greet = 'hello world'
-
-In []: greet.split()
-Out[]: ['hello', 'world']
-
-In []: line = 'Rossum, Guido, 54, 46, 55'
-
-In []: line.split(',')
-Out[]: ['Rossum', ' Guido', ' 54',
- ' 46', ' 55']
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Functions: Keyword arguments}
-We have seen the following
-\begin{lstlisting}
-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())
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}
- \frametitle{Summary}
- \begin{itemize}
- \item The \typ{def} keyword
- \item Docstrings
- \item Function arguments
- \begin{itemize}
- \item Default arguments
- \item Keyword arguments
- \end{itemize}
- \item Return values
- \end{itemize}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/least-square.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Least Square Fit}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
-Finding least square fit of given data-set
- \end{block}
- \begin{block}{Checklist}
- \begin{itemize}
- \item pendulum.txt
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{$L$ vs. $T^2$ - Scatter}
- \vspace{-0.15in}
- \begin{figure}
- \includegraphics[width=4in]{data/L-Tsq-points}
- \end{figure}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{$L$ vs. $T^2$ - Line}
- \vspace{-0.15in}
- \begin{figure}
- \includegraphics[width=4in]{data/L-Tsq-Line}
- \end{figure}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{$L$ vs. $T^2$ }
- \frametitle{$L$ vs. $T^2$ - Least Square Fit}
- \vspace{-0.15in}
- \begin{figure}
- \includegraphics[width=4in]{data/least-sq-fit}
- \end{figure}
-\end{frame}
-
-\begin{frame}
- \frametitle{Least Square Fit Curve}
- \begin{center}
- \begin{itemize}
- \item $L \alpha T^2$
- \item Best Fit Curve $\rightarrow$ Linear
- \begin{itemize}
- \item Least Square Fit
- \end{itemize}
-\item \typ{lstsq()}
- \end{itemize}
- \end{center}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{\typ{lstsq}}
- \begin{itemize}
- \item We need to fit a line through points for the equation $T^2 = m \cdot L+c$
- \item In matrix form, the equation can be represented as $T_{sq} = A \cdot p$, where $T_{sq}$ is
- $\begin{bmatrix}
- T^2_1 \\
- T^2_2 \\
- \vdots\\
- T^2_N \\
- \end{bmatrix}$
-, A is
- $\begin{bmatrix}
- L_1 & 1 \\
- L_2 & 1 \\
- \vdots & \vdots\\
- L_N & 1 \\
- \end{bmatrix}$
- and p is
- $\begin{bmatrix}
- m\\
- c\\
- \end{bmatrix}$
- \item We need to find $p$ to plot the line
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- Obtaining the least fit curve from a data set
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/lists.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Lists and Tuples}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Python data structures}
- \begin{itemize}
- \item Lists
- \item Tuples
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item Lists
- \begin{itemize}
- \item Initialization
- \item Operations
- \item Slicing
- \item Striding
- \end{itemize}
- \item Tuples
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/loadtxt.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-%%% This is from Fernando's setup.
-% \usepackage{color}
-% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
-% % Use and configure listings package for nicely formatted code
-% \usepackage{listings}
-% \lstset{
-% language=Python,
-% basicstyle=\small\ttfamily,
-% commentstyle=\ttfamily\color{blue},
-% stringstyle=\ttfamily\color{orange},
-% showstringspaces=false,
-% breaklines=true,
-% postbreak = \space\dots
-% }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Title page
-\title{Python for Scientific Computing : Plotting Experimental Data Contd.}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- \begin{itemize}
- \item Plotting experimental data from files - advanced
- \item Performing statistical operations in an efficient way
- \end{itemize}
- \end{block}
- \begin{block}{Checklist}
- \begin{itemize}
- \item pendulum.txt
- \end{itemize}
- \end{block}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Equations}
- \begin{itemize}
- \item We know that $ t = 2\pi \sqrt{\frac{l}{g}} $
- \item So $ g = \frac{4 \pi^2 l}{t^2} $
- \item Calculate ``g'' - acceleration due to gravity for each pair of L and T
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item loadtxt
- \item Basic operations/usage of arrays
- \item Statistical functions
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/loops.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Conditional flow and Loops}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- We shall be covering:
- \begin{itemize}
- \item Conditional statements: if-else
- \item Control flow: Loops
- \begin{itemize}
- \item while
- \item for
- \end{itemize}
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Python Script}
- \begin{block}{Problem statement}
- \begin{itemize}
- \item Prompt user for input
- \item Based on input prints:
- \begin{itemize}
- \item 'Be positive' if number is negative
- \item 'Zero' if number is zero
- \item 'Single' if number is one
- \item 'More' if number is greater than one
- \end{itemize}
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{\typ{while}}
-\begin{block}{Example: Fibonacci series}
- Sum of previous two elements defines the next
-\end{block}
-\begin{block}{Problem statement}
- Print all Fibonacci numbers less than 10.
-\end{block}
-\begin{block}{Expected output}
-\typ{1 1 2 3 5 8}\\
-\end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item Writing conditional statements
- \item While loops
- \item range function
- \item for and range
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/numbers.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Data types for Numbers}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- \begin{itemize}
- \item Number data types
- \item Operators
- \item Type conversion
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Kinds of Data Types}
- \begin{block}{Numbers}
- \begin{itemize}
- \item int
- \item float
- \item complex numbers
- \end{itemize}
- \end{block}
- \begin{block}{Conditional}
- bool
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item Data types for numbers
- \item operators
- \item type conversion
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/ode.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing: Ordinary Differential Equation}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
-Solving ordinary differential equations.
- \end{block}
- \begin{block}{Prerequisite}
- \begin{itemize}
- \item Understanding of Arrays.
- \item functions and lists
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{Solving ODEs using SciPy}
-\begin{itemize}
-\item Let's consider the spread of an epidemic in a population
-\item $\frac{dy}{dt} = ky(L-y)$ gives the spread of the disease
-\item L is the total population.
-\item Use L = 250000, k = 0.00003, y(0) = 250
-\end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{ODEs - Simple Pendulum}
-We shall use the simple ODE of a simple pendulum.
-\begin{equation*}
-\ddot{\theta} = -\frac{g}{L}sin(\theta)
-\end{equation*}
-\begin{itemize}
-\item This equation can be written as a system of two first order ODEs
-\end{itemize}
-\begin{align}
-\dot{\theta} &= \omega \\
-\dot{\omega} &= -\frac{g}{L}sin(\theta) \\
- \text{At}\ t &= 0 : \nonumber \\
- \theta = \theta_0(10^o)\quad & \&\quad \omega = 0\ (Initial\ values)\nonumber
-\end{align}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- Solving ordinary differential equations
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/plotting-files.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-%%% This is from Fernando's setup.
-% \usepackage{color}
-% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
-% % Use and configure listings package for nicely formatted code
-% \usepackage{listings}
-% \lstset{
-% language=Python,
-% basicstyle=\small\ttfamily,
-% commentstyle=\ttfamily\color{blue},
-% stringstyle=\ttfamily\color{orange},
-% showstringspaces=false,
-% breaklines=true,
-% postbreak = \space\dots
-% }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Title page
-\title{Python for Scientific Computing : Plotting Experimental Data}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- Plotting experimental data via lists or files
- \end{block}
- \begin{block}{Checklist}
- \begin{itemize}
- \item pendulum.txt
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{lists}
- \begin{itemize}
- \item Creation.
- \item Appending.
- \item Iterating through list.
- \end{itemize}
- \end{block}
- \begin{block}{Data processing}
- \begin{itemize}
- \item In form of lists.
- \item Handling files.
- \item for loops
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/solving-equations.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Solving Equations}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
-Using arrays to find solutions and roots or equations.
- \end{block}
- \begin{block}{Prerequisite}
- Understanding of Arrays.
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{Solution of equations}
-Consider,
- \begin{align*}
- 3x + 2y - z & = 1 \\
- 2x - 2y + 4z & = -2 \\
- -x + \frac{1}{2}y -z & = 0
- \end{align*}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{Scipy Methods - \typ{roots}}
-\begin{itemize}
-\item Calculates the roots of polynomials
-\item To calculate the roots of $x^2-5x+6$
-\end{itemize}
-\begin{lstlisting}
- In []: coeffs = [1, -5, 6]
- In []: roots(coeffs)
- Out[]: array([3., 2.])
-\end{lstlisting}
-\vspace*{-.2in}
-\begin{center}
-\includegraphics[height=1.6in, interpolate=true]{data/roots}
-\end{center}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{Scipy Methods - \typ{fsolve}}
-\begin{small}
-\begin{lstlisting}
- In []: from scipy.optimize import fsolve
-\end{lstlisting}
-\end{small}
-\begin{itemize}
-\item Finds the roots of a system of non-linear equations
-\item Input arguments - Function and initial estimate
-\item Returns the solution
-\end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item Solving linear equations
- \item Finding roots
- \item Roots of non linear equations
- \item Basics of Functions
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/statistics.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Large Scale Data Processing}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- We read and process large data file to solve a problem.
- \end{block}
- \begin{block}{Checklist}
- \begin{itemize}
- \item sslc.txt
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Structure of the file}
- Understanding the structure of sslc.txt
- \begin{itemize}
- \item 180,000 lines.
- \item Each line in the file has a student's details(record)
- \item Each record consists of fields separated by ';'
- \end{itemize}
-\end{frame}
-
-\begin{frame}
- \frametitle{Structure of the file \ldots}
-\emphbar{A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;;}
- Each record consists of:
- \begin{itemize}
- \item Region Code : 'A'
- \item Roll Number : '015163'
- \item Name : 'JOSEPH RAJ S'
- \item Marks of 5 subjects: English(083), Hindi(042), Maths(47), Science(AA), Social(72)
- \item Total marks : 244
- \item Pass/Fail (P/F) : ' '
- \item Withheld (W) : ' '
- \end{itemize}
-\end{frame}
-
-%% \begin{frame}
-%% \frametitle{Statistical Analysis: Problem statement}
-%% 1. Read the data supplied in the file \emph{sslc.txt} and carry out the following:
-%% \begin{block}{}
-%% Draw a pie chart representing proportion of students who scored more than 90\% in each region in Science.
-%% \end{block}
-%% \end{frame}
-
-\begin{frame}
- \frametitle{Problem statement: explanation}
- \emphbar{Draw a pie chart representing proportion of students who scored more than 90\% in each region in Science.}
- \begin{columns}
- \column{5.25\textwidth}
- \hspace*{.5in}
- \includegraphics[height=2.6in, interpolate=true]{data/science}
- \column{0.8\textwidth}
-\end{columns}
-\end{frame}
-
-\begin{frame}
- \frametitle{Machinery Required}
- \begin{itemize}
- \item File reading
- \item Dictionaries
- \item Parsing
- \item Plot
- \end{itemize}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{Data processing}
- \begin{itemize}
- \item Dictionaries
- \item String parsing
- \item Pie charts
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/presentations/strings.tex Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-% Title page
-\title{Python for Scientific Computing : Strings and I/O operations}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date{}
-
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-\begin{frame}
- \frametitle{About the Session}
- \begin{block}{Goal}
- \begin{itemize}
- \item Strings and their manipulations
- \item I/O operations
- \end{itemize}
- \end{block}
- \begin{block}{Prerequisites}
- \begin{itemize}
- \item Writing Python scripts
- \item Basics of Lists
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Summary}
- \begin{block}{}
- \begin{itemize}
- \item Creating string variables
- \item Manipulating strings
- \item I/O operations
- \item Comments
- \item Dynamically typed nature
- \end{itemize}
- \end{block}
-\end{frame}
-
-\begin{frame}
- \frametitle{Thank you!}
- \begin{block}{}
- This session is part of \textcolor{blue}{FOSSEE} project funded by:
- \begin{center}
- \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
- \end{center}
- \end{block}
-\end{frame}
-
-\end{document}
--- a/solving-equations.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-* Solving Equations
-*** Outline
-***** Introduction
-******* What are we going to do?
-******* How are we going to do?
-******* Arsenal Required
-********* working knowledge of arrays
-
-*** Script
- Welcome.
-
- In this tutorial we shall look at solving linear equations, obtaining
- roots of polynomial and non-linear equations. In the process, we
- shall look at defining functions as well.
-
- We would be using concepts related to arrays which we have covered
- in a previous tutorial.
-
- Let's begin with solving linear equations.
- {show a slide of the equations}
- Consider the set of equations,
- 3x + 2y -z = 1, 2x-2y + 4z = -2, -x+ half y-z = 0.
- We shall use the solve function, to solve the given system of linear
- equations. Solve requires the coefficients and the constants to
- be in the form of matrices of the form Ax = b to solve the system of linear equations.
-
- Lets start ipython -pylab interpreter.
- We begin by entering the coefficients and the constants as
- matrices.
-
- In []: A = array([[3,2,-1],
- [2,-2,4],
- [-1, 0.5, -1]])
-
- A is a 3X3 matrix of the coefficients of x, y and z
-
- In []: b = array([1, -2, 0])
-
- Now, we can use the solve function to solve the given system.
-
- In []: x = solve(A, b)
-
- Type x, to look at the solution obtained.
-
- Equation is of the form Ax = b, so we verify the solution by
- obtaining a matrix product of A and x, and comparing it with b.
- As we have covered earlier that we should use the dot function
- here, and not the * operator.
-
- In []: Ax = dot(A, x)
- In []: Ax
-
- The result Ax, doesn't look exactly like b, but if we carefully
- observe, we will see that it is the same as b. To save ourself
- all this trouble, we can use the allclose function.
-
- allclose checks if two matrices are close enough to each other
- (with-in the specified tolerance level). Here we shall use the
- default tolerance level of the function.
-
- In []: allclose(Ax, b)
- The function returns True, which implies that the product of A &
- x is very close to the value of b. This validates our solution x.
-
- Let's move to finding the roots of a polynomial. We shall use the
- roots function for this.
-
- The function requires an array of the coefficients of the
- polynomial in the descending order of powers.
- Consider the polynomial x^2-5x+6 = 0
-
- In []: coeffs = [1, -5, 6]
- In []: roots(coeffs)
- As we can see, roots returns the result in an array.
- It even works for polynomials with imaginary roots.
- roots([1, 1, 1])
- As you can see, the roots of that equation are of the form a + bj
-
- What if I want the solution of non linear equations?
- For that we use the fsolve function. In this tutorial, we shall use
- the equation sin(x)+cos^2(x). fsolve is not part of the pylab
- package which we imported at the beginning, so we will have to import
- it. It is part of scipy package. Let's import it using.
-
- In []: from scipy.optimize import fsolve
-
- Now, let's look at the documentation of fsolve by typing fsolve?
-
- In []: fsolve?
-
- As mentioned in documentation the first argument, func, is a python
- function that takes atleast one argument. So, we should now
- define a python function for the given mathematical expression
- sin(x)+cos^2(x).
-
- The second argument, x0, is the initial estimate of the roots of
- the function. Based on this initial guess, fsolve returns a root.
-
- Before, going ahead to get a root of the given expression, we
- shall first learn how to define a function in python.
- Let's define a function called f, which returns values of the
- given mathematical expression (sin(x)+cos^2(x)) for a each input.
-
- In []: def f(x):
- ... return sin(x)+cos(x)*cos(x)
- ...
- ...
- hit the enter key to come out of function definition.
-
- def, is a key word in python that tells the interpreter that a
- function definition is beginning. f, here, is the name of the
- function and x is the lone argument of the function. The whole
- definition of the function is done with in an indented block similar
- to the loops and conditional statements we have used in our
- earlier tutorials. Our function f has just one line in it's
- definition.
-
- We can test our function, by calling it with an argument for
- which the output value is known, say x = 0. We can see that
- sin(x) + cos^2(x) has a value of 1, when x = 0.
-
- Let's check our function definition, by calling it with 0 as an
- argument.
- In []: f(0)
- We can see that the output is as expected.
-
- Now, that we have our function, we can use fsolve to obtain a root
- of the expression sin(x)+cos^2(x). Recall that fsolve takes
- another argument, the initial guess. Let's use 0 as our initial
- guess.
-
- In []: fsolve(f, 0)
- fsolve has returned a root of sin(x)+cos^2(x) that is close to 0.
-
- That brings us to the end of this tutorial. We have covered solution
- of linear equations, finding roots of polynomials and non-linear
- equations. We have also learnt how to define functions and call
- them.
-
- Thank you!
-
-*** Notes
--- a/statistics-script Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-Hello friends and welcome to the third tutorial in the series of tutorials on "Python for scientific computing."
-
-This session is a continuation of the tutorial on Plotting Experimental data.
-
-We shall look at plotting experimental data using slightly advanced methods here. And then look into some statistical operations.
-
-In the previous tutorial we learnt how to read data from a file and plot it.
-We used 'for' loops and lists to get data in the desired format.
-IPython -Pylab also provides a function called 'loadtxt' that can get us the same data in the desired format without much hustle.
-
-We shall use the same pendulum.txt file that we used in the previous session.
-We know that, pendulum.txt contains two columns, with length being first and time period is second column, so to get both columns in two separate variables we type
-
-l, t = loadtxt('pendulum.txt', unpack=True)
-
-(unpack = True) will give us all the data in the first column which is the length in l and all the data in the second column which is the time period in t. Here both l and t are arrays. We shall look into what arrays are in subsequent tutorials.
-
-to know more about loadtxt type
-
-loadtxt?
-This is a really powerful tool to load data directly from files which are well structured and formatted. It supports many features like getting selected columns only, or skipping rows.
-
-Let's back to the problem, hit q to exit. Now to get squared values of t we can simply do
-
-tsq = t*t
-
-Note that we don't have to use the 'for' loop anymore. This is the benefit of arrays. If we try to do the something similar using lists we won't be able to escape the use of the 'for' loop.
-
-Let's now plot l vs tsq just as we did in the previous session
-
-plot(l, tsq, 'o')
-
-Let's continue with the pendulum expt to obtain the value of the acceleration due to gravity. The basic equation for finding Time period of simple pendulum is:
-
-T = 2*pi*sqrt(L/g)
-
-rearranging this equation we obtain the value of as
-g = 4 pi squared into l by t squared.
-
-In this case we have the values of t and l already, so to find g value for each element we can simply use:
-
-g = 4*pi^2*L/T^2
-
-g here is array, we can take the average of all these values to get the acceleration due to gravity('g') by
-
-print mean(g)
-
-Mean again is provided by pylab module which calculates the average of the given set of values.
-There are other handy statistical functions available, such as median, mode, std(for standard deviation) etc.
-
-In this small session we have covered 'better' way of loading data from text files.
-Why arrays are a better choice than lists in some cases, and how they are more helpful with mathematical operations.
-
-Hope it was useful to you. Thank you!
------------------------------------------------------------------------------------------------------------
-In this tutorial we shall learn how to compute statistics using python.
-We also shall learn how to represent data in the form of pie charts.
-
-Let us start with the most basic need in statistics, the mean.
-
-We shall calculate the mean acceleration due to gravity using the same 'pendulum.txt' that we used in the previous session.
-
-As we know, 'pendulum.txt' contains two values in each line. The first being length of pendulum and second the time period.
-To calculate acceleration due to gravity from these values, we shall use the expression T = 2*pi*sqrt(L/g)
-So re-arranging this equation, we get g = 4*pi**2*L/T**2 .
-
-We shall calculate the value of g for each pair of L and t and then calculate mean of all those g values.
-
-## if we do loadtxt and numpy arrays then this part will change
- First we need something to store each value of g that we are going to compute.
- So we start with initialising an empty list called `g_list'.
-
- Now we read each line from the file 'pendulum.txt' and calculate g value for that pair of L and t and then append the computed g to our `g_list'.
-
- In []: for line in open('pendulum.txt'):
- .... point = line.split()
- .... L = float(point[0])
- .... t = float(point[1])
- .... g = 4 * pi * pi * L / (t * t)
- .... g_list.append(g)
-
- The first four lines of this code must be trivial. We read the file and store the values.
- The fifth line where we do g equals to 4 star pi star and so on is the line which calculates g for each pair of L and t values from teh file. The last line simply stores the computed g value. In technical terms appends the computed value to g_list.
-
- Let us type this code in and see what g_list contains.
-###############################
-
-Each value in g_list is the g value computed from a pair of L and t values.
-
-Now we have all the values for g. We must find the mean of these values. That is the sum of all these values divided by the total no.of values.
-
-The no.of values can be found using len(g_list)
-
-So we are left with the problem of finding the sum.
-We shall create a variable and loop over the list and add each g value to that variable.
-lets call it total.
-
-In []: total = 0
-In []: for g in g_list:
- ....: total += g
- ....:
-
-So at of this piece of code we will have the sum of all the g values in the variable total.
-
-Now calculating mean of g is as simple as doing total divided by len(g_list)
-
-In []: g_mean = total / len(g_list)
-In []: print 'Mean: ', g_mean
-
-If we observe, we have to write a loop to do very simple thing such as finding sum of a list of values.
-Python has a built-in function called sum to ease things.
-
-sum takes a list of values and returns the sum of those values.
-now calculating mean is much simpler.
-we don't have to write any for loop.
-we can directly use mean = sum(g_list) / len(g_list)
-
-Still calculating mean needs writing an expression.
-What if we had a built-in for calculating mean directly.
-We do have and it is available through the pylab library.
-
-Now the job of calculating mean is just a function away.
-Call mean(g_list) directly and it gives you the mean of values in g_list.
-
-Isn't that sweet. Ya and that is why I use python.
-
-
--- a/statistics.txt Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-Hello and welcome to the tutorial on handling large data files and processing them.
-
-Up until now we have covered:
-* How to create plots.
-* How to read data from files and process it.
-
-In this tutorial, we shall use these concepts and some new ones, to solve a problem/exercise.
-
-We have a file named sslc.txt on our desktop.
-It contains record of students and their performance in one of the State Secondary Board Examination. It has 180, 000 lines of record. We are going to read it and process this data.
-We can see the content of file by double clicking on it. It might take some time to open since it is quite a large file.
-Please don't edit the data.
-This file has a particular structure. Each line in the file is a set of 11 fields separated by semi-colons
-Consider a sample line from this file.
-A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;;
-The following are the fields in any given line.
-* Region Code which is 'A'
-* Roll Number 015163
-* Name JOSEPH RAJ S
-* Marks of 5 subjects:
- ** English 083
- ** Hindi 042
- ** Maths 47
- ** Science AA (Absent)
- ** Social 72
-* Total marks 244
-* Pass/Fail - This field is blank here because the particular candidate was absent for an exam if not it would've been one of (P/F)
-* Withheld - Again blank in this case(W)
-
-Let us now look at the problem we wish to solve:
-Draw a pie chart representing the proportion of students who scored more than 90% in each region in Science.
-
-This is the result we expect:
-#slide of result.
-
-In order to solve this problem, we need the following machinery:
-File Reading - which we have already looked at.
-parsing - which we have looked at partially.
-Dictionaries - we shall be introducing the concept of dictionaries here.
-And finally plotting - which we have been doing all along.
-
-Since this file is on our Desktop, let's navigate by typing
-
-cd Desktop
-
-Let's get started, by opening the IPython prompt by typing,
-
-ipython -pylab
-
-Let's first start off with dictionaries.
-
-We earlier used lists briefly. Back then we just created lists and appended items into them.
-x = [1, 4, 2, 7, 6]
-In order to access any element in a list, we use its index number. Index starts from 0.
-For eg. x[0] gives 1 and x[3] gives 7.
-
-But, using integer indexes isn't always convenient. For example, consider a telephone directory. We give it a name and it should return a corresponding number. A list is not well suited for such problems. Python's dictionaries are better, for such problems. Dictionaries are just key-value pairs. For example:
-
-d = {'png' : 'image',
- 'txt' : 'text',
- 'py' : 'python'}
-
-And that is how we create a dictionary. Dictionaries are created by typing the key-value pairs within flower brackets.
-
-d
-
-d is a dictionary. The first element in the pair is called the `key' and the second is called the `value'. The key always has to be a string while the value can be of any type.
-
-Lists are indexed by integers while dictionaries are indexed by strings. They are indexed using their keys as shown
-In []: d['txt']
-Out[]: 'text'
-
-In []: d['png']
-Out[]: 'image'
-
-The dictionaries can be searched for the presence of a certain key by typing
-'py' in d
-True
-
-'jpg' in d
-False
-
-
-
-Please note that keys, and not values, are searched.
-'In a telephone directory one can search for a number based on a name, but not for a name based on a number'
-
-to obtain the list of all keys in a dictionary, type
-d.keys()
-['py', 'txt', 'png']
-
-Similarly,
-d.values()
-['python', 'text', 'image']
-is used to obtain the list of all values in a dictionary
-
-one more thing to note about dictionaries, in this case for d,
-
-d
-
-is that dictionaries do not preserve the order in which the items were entered. The order of the elements in a dictionary should not be relied upon.
-
-------------------------------------------------------------------------------------------------------------------
-
-Parsing and string processing
-
-As we saw previously we shall be dealing with lines with content of the form
-A;015162;JENIL T P;081;060;77;41;74;333;P;;
-Here ';' is delimiter, that is ';' is used to separate the fields.
-
-We shall create one string variable to see how can we process it to get the desired output.
-
-line = 'A;015162;JENIL T P;081;060;77;41;74;333;P;;'
-
-Previously we saw how to split on spaces when we processed the pendulum.txt file. Let us now look at how to split a string into a list of fields based on a delimiter other than space.
-a = line.split(';')
-
-Let's now check what 'a' contains.
-
-a
-
-is list containing all the fields separately.
-
-a[0] is the region code, a[1] the roll no., a[2] the name and so on.
-Similarly, a[6] gives us the science marks of that particular region.
-
-So we create a dictionary of all the regions with number of students having more than 90 marks.
-
-------------------------------------------------------------------------------------------------------------------
-
-Let's now start off with the code
-
-We first create an empty dictionary
-
-science = {}
-now we read the records, one by one from the file sslc.txt
-
-for record in open('sslc.txt'):
-
- we split each record on ';' and store it in a list by: fields equals record.split(';')
-
- now we get the region code of a particular entry by region_code equal to fields[0].strip.
-The strip() is used to remove all leading and trailing white spaces from a given string
-
- now we check if the region code is already there in dictionary by typing
- if region_code not in science:
- when this statement is true, we add new entry to dictionary with initial value 0 and key being the region code.
- science[region_code] = 0
-
- Note that this if statement is inside the for loop so for the if block we will have to give additional indentation.
-
- we again come back to the older, 'for' loop's, indentation and get the science marks by
- score_str = fields[6].strip()
-
- we check if student was not absent
- if score_str != 'AA':
- then we check if his marks are above 90 or not
- if int(score_str) > 90:
- if yes we add 1 to the value of dictionary for that region by
- science[region_code] += 1
-
- Hit return twice to exit the for loop
-
-by end of this loop we shall have our desired output in the dictionary 'science'
-we can check the values by
-science
-
-now to create a pie chart we use
-
-pie(science.values(),labels = science.keys())
-
-the first argument to the pie function is the values to be plotted. The second is an optional argument which is used to label the regions.
-
-title('Students scoring 90% and above in science by region')
-savefig('science.png')
-
-That brings us to the end of this tutorial. We have learnt about dictionaries, some basic string parsing and plotting pie chart in this tutorial. Hope you have enjoyed it. Thank you.
-#slide of summary.
--- a/strings.org Mon Sep 13 18:35:56 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,214 +0,0 @@
-* Strings
-*** Outline
-***** Strings
-******* basic manipulation
-******* operations
-******* immutability
-******* string methods
-******* split and join
-******* formatting - printf style
-***** Simple IO
-******* raw_input
-******* console output
-***** Odds and Ends
-******* dynamic typing
-******* comments
-***** Arsenal Required
-******* lists
-******* writing to files
-*** Script
- Welcome friends.
-
- In the previous tutorial we have looked at data types for dealing
- with numbers. In this tutorial we shall look at strings. We shall
- look at how to do elementary string manipulation, and simple input
- and output operations.
-
- In this tuotrial we shall use concepts of writing python scripts and
- basics of lists that have been covered in previous session
-
- Lets get started by opening ipython interpreter.
- We shall create some
- a string by typing
-
- a = open single quote 'This is a string' close single quote
- print a
- a contains the string
- we can check for datatype of a by using type(a) and shows it is 'str'
-
- consider the case when string contains single quote.
- for example I'll be back
- to store these kind of strings, we use double quotes
- type
- b = open double quote "I'll be back" close double quote
- print b ptints the value
-
- IN python, anything enlosed in quotes is a string. Does not matter
- if they are single quotes or double quotes.
-
- There is
- also a special type of string enclosed in triple single quotes or triple double
- quotes.
-
- so when you do
- c = '''Iam also a string'''
- print c
- and c is also string variable
- and even
- d = """And one more."""
- print d
- d is also a string
-
- These strings enclosed in triple quotes are special type of strings, called docstrings, and they shall
- be discussed in detail along with functions
-
- We know elements in lists and arrays can be accessed with indices.
- similarly string elements
- can also be accessed with their indexes. and here also, indexing starts from 0
-
- so
- print a[0] gives us 'T' which is the first character
- print a[5] gives us 'i' which is 6th character.
-
- The len function, which we used with lists and arrays, works with
- strings too.
- len(a) gives us the length of string a
-
- Python's strings support the + and * operations
- + concatenates two strings.
- so a + b gives us the two srtings concatenated
- and * is used for replicating a string for given number of times.
- so a * 4 gives us a replicated 4 times
-
- What do you think would happen when you do a * a?
- It's obviously an error since, it doesn't make any logical sense.
-
- One thing to note about strings, is that they are immutable, which means when yo do
- a[0] = 't'it throws an error
-
- Then how does one go about doing strings manipulations. Python provides
- 'methods' for doing various manipulations on strings. For example -
-
- a.upper() returns a string with all letters capitalized.
-
- and a.lower() returns a string with all smaller case letters.
-
- there are many other methods available and we shall use Ipython auto suggestion feature to find out
-
- type a. and hit tab
- we can see there are many methods available in python for string manipulation
-
- lets us try startswith
- a.startswith('Thi')
- returns True if the string starts with the argument passed.
-
- similarly there's endswith
- a.endswith('ING')
-
- We've seen the use of split function in the previous
- tutorials. split returns a list after splitting the string on the
- given argument.
- alist = a.split()
- will give list with four elements.
- print alist
-
- Python also has a 'join' function, which does the opposite of what
- split does.
- ' '.join(alist) will return the original string a.
- This function takes list of elements(in our case alist) to be joined.
- '-'.join(alist) will return a string with the spaces in the string
- 'a' replaced with hyphens.
-
- please note that after all these operations, the original string is not changed.
- and print a prints the original string
-
- At times we want our output or message in a particular
- format with variables embedded, something like printf in C. For
- those situations python provides a provision. First lets create some
- variables say
-
- In []: x, y = 1, 1.234
-
- In []: print 'x is %s, y is %s' %(x, y)
- Out[]: 'x is 1, y is 1.234'
- Here %s means string, you can also try %d or %f for integer and
- float values respectively.
- * formatting - printf style *
-
- we have seen how to output data
- Now we shall look at taking input from the console.
-
- The raw_input function allows us to take input from the console.
- type a = raw_input() and hit enter
- now python is waiting for input
- type 5 and hit enter
-
- we can check for the value of a by typing print a and we see that it is 5
-
- raw_input also allows us to give a prompt string.
- we type
- a = raw_input("Enter a value: ")
- and we see that the string given as argument is prompted at the user.
- 5
- Note that a, is now a string variable and not an integer.
- type(a)
- raw_input takes input only as a string
-
- we cannot do mathematical operations on it
- but we can use type conversion similar to that shown in previous tutorial
-
- b = int(a)
- a has now been converted to an integer and stored in b
- type(b) gives int
- b can be used here for mathematical operations.
-
- For console output, we have been using print which is pretty straightforward.
-
- We shall look at a subtle feature of the print statement.
-
- Open scite editor and type
- print "Hello"
- print "World"
- We save the file as hello1.py run it from the ipython interpreter. Make
- sure you navigate to the place, where you have saved it.
- %run hello1.py
-
- Now we make a small change to the code snippet and save it in the
- file named "hello2.py"
- print "Hello",
- print "World"
- We now run this file, from the ipython interpreter.
- %run hello2.py
-
-
- Note the difference in the output.
- The comma adds a space at the end of the line, instead
- of a new line character that is normally added.
-
- Before we wind up, a couple of miscellaneous things.
- As you may have already noticed, Python is a dynamically typed
- language, that is you don't have to specify the type of a variable
- when using a new one. You don't have to do anything special, to 'reuse'
- a variable that was of int type as a float or string.
-
- a = 1 and here a is integer
- lets store a float value in a by doing
- a = 1.1
- and print a
- now a is float
- a = "Now I am a string!"
-
- Comments in Python start with a pound or hash sign. Anything after
- a #, until the end of the line is considered a comment, except of
- course, if the hash is in a string.
- a = 1 # in-line comments
-
- pritn a and we see that comment is not a part of variable a
-
- a = "# not a comment"
-
- we come to the end of this tutorial on strings
- In this tutorial we have learnt what are supported operations on strings
- and how to perform simple Input and Output operations in Python.
-
-*** Notes