# HG changeset patch # User Puneeth Chaganti # Date 1286517729 -19800 # Node ID 0ff3f1a97068fe28418414a79318fa28f587d195 # Parent 9bc78792904ba4558581583dc4dab16fb4a6fab0# Parent c507e9c413c6262b3b6d975afc3222a1514a4176 Merged heads. diff -r c507e9c413c6 -r 0ff3f1a97068 accessing-pieces-arrays/script.rst --- a/accessing-pieces-arrays/script.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/accessing-pieces-arrays/script.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,22 +1,21 @@ .. Objectives .. ---------- - By the end of this tutorial, you will be able to: + .. By the end of this tutorial, you will be able to: - 1. Access and change individual elements of arrays, both one - dimensional and multi-dimensional. - 2. Access and change rows and columns of arrays. - 3. Access and change other chunks from an array, using slicing - and striding. - 4. Read images into arrays and perform processing on them, using - simple array manipulations. + .. 1. Access and change individual elements of arrays, both one + .. dimensional and multi-dimensional. + .. 2. Access and change rows and columns of arrays. + .. 3. Access and change other chunks from an array, using slicing + .. and striding. + .. 4. Read images into arrays and perform processing on them, using + .. simple array manipulations. .. Prerequisites .. ------------- -.. 1. Name of LO-1 -.. 2. Name of LO-2 -.. 3. Name of LO-3 +.. 1. getting started with arrays + .. Author : Puneeth Internal Reviewer : diff -r c507e9c413c6 -r 0ff3f1a97068 advanced-features-functions/questions.rst --- a/advanced-features-functions/questions.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/advanced-features-functions/questions.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,17 +1,108 @@ -Objective ---------- +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. All arguments of a function cannot have default values. True or + False? + + Answer: False + +#. When calling a function, the arguments + + 1. should always be in the order in which they are defined. + #. can be in any order + #. only keyword arguments can be in any order, but should be called + at the beginning. + #. only keyword arguments can be in any order, but should be called + at the end. -.. A mininum of 8 questions here. +#. Given the following function, identify the keywords with default + values. + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + Answer: ``count``, ``show`` -1. Question 1 -2. Question 2 -3. Question 3 +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", 1, True)``. + + Answer: ``+`` is printed and returned. -Programming ------------ +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", True, 1)``. + + Answer: ``+`` is printed and returned. + +#. Given the following function, + :: + + def seperator(char, count=40, show=False): + + if show: + print char * count + + return char * count + + What is the output of ``separator("+", show=True, 1)``. + + Answer: SyntaxError -.. A minimum of 2 questions here. +#. The following is a valid function definition. True or False? Why? + :: + + def seperator(count=40, char, show=False): + + if show: + print char * count + + return char * count + + Answer: False. All parameters with default arguments should be + defined at the end. -1. Programming Assignment 1 -2. Programming Assignment 2 +#. Which of the following cannot be used as default values for + arguments? + + a. floats + #. lists + #. functions + #. booleans + #. None of the Above + + Answer: None of the above. + + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. + +2. diff -r c507e9c413c6 -r 0ff3f1a97068 advanced-features-functions/script.rst --- a/advanced-features-functions/script.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/advanced-features-functions/script.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,17 +1,40 @@ -======== - Script -======== +.. Objectives +.. ---------- + +.. At the end of this tutorial, you will be able to + +.. 1. Assign default values to arguments, when defining functions +.. 2. Define and call functions with keyword arguments. +.. 3. Also, you will get a glimpse of the plethora of functions +.. available, in Python standard library and the scientific computing +.. libraries. + -{{{ show the welcome slide }}} +.. Prerequisites +.. ------------- + +.. 1. getting started with ipython +.. #. getting started with functions + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + +{{{ Show the slide containing title }}} Welcome to the tutorial on advanced feature of functions. -{{{ show the outline slide }}} +{{{ Show the outline slide }}} In this tutorial we shall be looking at specifying default arguments to functions when defining them and calling functions using keyword arguments. We shall also, look at some of the built-in functions -available in the standard library of Python. +available in the standard library of Python and the scientific +computing libraries. {{{ switch to terminal }}} @@ -46,7 +69,7 @@ linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi linspace(0, 2*pi) # returns 50 points between 0 and 2pi -#[punch: all above content goes on to a slide] +.. #[punch: all above content goes on to a slide] {{{ switch back to ipython }}} @@ -76,10 +99,13 @@ "Hello" is treated as the ``greet`` and we get "Hello World" as the output. "World" is the default value for the argument ``name``. -E%% %% Pause the video here and redefine the function ``welcome``, by -interchanging it's arguments. Place the ``name`` argument with it's -default value of "Hello" before the ``greet`` argument. Then, resume -the video. +Following is an (are) exercise(s) that you must do. + +%%1%% Redefine the function ``welcome``, by interchanging it's +arguments. Place the ``name`` argument with it's default value of +"Hello" before the ``greet`` argument. + +Please, pause the video here. Do the exercise and then continue. :: @@ -90,17 +116,24 @@ default argument``. When defining a function all the argument with default values should come at the end. -E%% %% Pause the video here and type ``linspace?`` to see the -definition of the command and notice how all the arguments with -default values are towards the end. +Following is an exercise that you must do. + +%%2%% See the definition of linspace using ``?`` and observe how all +the arguments with default values are towards the end. + +Please, pause the video here. Do the exercise and then continue. :: linspace? -E%% %% Pause the video here and redefine the function ``welcome`` with -a default value of "Hello" to the ``greet`` argument. Then, call the -function without any arguments. Then, resume the video. +Following is an exercise that you must do. + +%%3%% Redefine the function ``welcome`` with a default value of +"Hello" to the ``greet`` argument. Then, call the function without any +arguments. + +Please, pause the video here. Do the exercise and then continue. :: @@ -175,8 +208,8 @@ Math functions - abs, sin, .... -#[punch: Need to decide, exactly what to put here. Reviewer comments - welcome.] +.. #[punch: Need to decide, exactly what to put here. Reviewer comments +.. welcome.] {{{ switch to slide showing classes of functions in pylab, scipy }}} @@ -192,7 +225,7 @@ scipy (modules) fftpack, stats, linalg, ndimage, signal, optimize, integrate -{{{ switch slide to summary slide }}} +{{{ Show summary slide }}} That brings us to the end of this tutorial. In this tutorial we have learnt how to use functions with default values and keyword @@ -200,4 +233,9 @@ Python standard library and the Scientific Computing related packages. -Thank You! +{{{ Show the "sponsored by FOSSEE" slide }}} + +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India + +Hope you have enjoyed and found it useful. +Thank you! diff -r c507e9c413c6 -r 0ff3f1a97068 getting-started-files/pendulum.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-files/pendulum.txt Fri Oct 08 11:32:09 2010 +0530 @@ -0,0 +1,90 @@ +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 diff -r c507e9c413c6 -r 0ff3f1a97068 getting-started-files/questions.rst --- a/getting-started-files/questions.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/getting-started-files/questions.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,17 +1,134 @@ -Objective ---------- +Objective Questions +------------------- .. A mininum of 8 questions here. -1. Question 1 -2. Question 2 -3. Question 3 +1. What function is used to open a file? + + Answer: ``open`` + +#. The ``open`` function returns a + + a. string + #. list + #. file object + #. function + + Answer: file object + +#. ``open`` function opens a file by default in write mode. T or F? + + Answer: False + +#. The ``read`` method reads a file and returns the contents + + a. string + #. list + #. file object + #. None of the above + + Answer: string + +#. Given a file with ``hello.txt``, which looks like + :: + + Hello, World! + + What is the value of content, at the end of this code block:: + + f = open('hello.txt') + content = f.read() + content = f.read() + f.close() + + Answer: It is a null string. + +#. The following code block prints each line of ``hello.txt``:: + + f = open('hello.txt') + for line in f.read(): + print line + + True or False? + + Answer: False + +#. Given a file with ``hello.txt``, which looks like + :: + + Hello, World! + + What is the output of :: + + f = open('hello.txt') + + for line in f: + print line + + for line in f: + print line + + f.close() + + Answer: Hello, World! is printed once. + + .. The actual answer should talk about blank lines, but I'm + .. not sure if we should get into such detail. + + .. Should this be made a multiple-choice? + + +#. Given a file with ``hello.txt``, which looks like + :: + + Hello, World! + + What is the output of :: + + f = open('hello.txt') + + for line in f: + print line + + f.close() + + for line in f: + print line + + f.close() + + Answer: Hello, World! is printed twice. + +#. Given a file with ``hello.txt``, which looks like + :: + + Hello, World! + + What is the output of :: + + f = open('hello') + + for line in f: + print line + + f.close() + + for line in f: + print line + + f.close() + + Answer: IOError - No such file or directory: 'hello' -Programming ------------ +Larger Questions +---------------- .. A minimum of 2 questions here. -1. Programming Assignment 1 -2. Programming Assignment 2 +1. f.read(size) + +#. Print every alternate line of a file, starting at the first line. + +#. Print the file in reverse. Starting from the last line to the + first. diff -r c507e9c413c6 -r 0ff3f1a97068 getting-started-files/script.rst --- a/getting-started-files/script.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/getting-started-files/script.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,10 +1,30 @@ -======== - Script -======== +.. Objectives +.. ---------- + +.. By the end of this tutorial, you will be able to +.. 1. Open and read the contents of a file. +.. #. Read files line by line. +.. #. Read all the contents of the file at once. +.. #. Close open files. + +.. Prerequisites +.. ------------- -Welcome to the tutorial on getting started with files. +.. 1. getting started with ipython +.. #. getting started with lists +.. #. getting started with for + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] -{{{ Screen shows welcome slide }}} +Script +------ + +{{{ Show the slide containing title }}} + +Hello Friends. Welcome to the tutorial on getting started with files. {{{ Show the outline for this tutorial }}} @@ -33,7 +53,8 @@ f The file object shows, the file which is open and the mode (read -or write) in which it is open. +or write) in which it is open. Notice that it is open in read only +mode, here. We shall first learn to read the whole file into a single variable. Later, we shall look at reading it line-by-line. We use @@ -54,24 +75,29 @@ pend -%%1%% Pause the video here and split the variable into a list, -``pend_list``, of the lines in the file and then resume the -video. Hint, use the tab command to see what methods the string -variable has. +Following is an exercise that you must do. + +%%1%% Split the variable into a list, ``pend_list``, of the lines in +the file. Hint, use the tab command to see what methods the string +variable has. -#[punch: should this even be put? add dependency to strings LO, -where we mention that strings have methods for manipulation. hint: -use splitlines()] +Please, pause the video here. Do the exercise and then continue. + +.. #[punch: should this even be put? add dependency to strings LO, +.. where we mention that strings have methods for manipulation. hint: +.. use splitlines()] + :: pend_list = pend.splitlines() pend_list -Now, let us learn to read the file line-by-line. But, before that -we will have to close the file, since the file has already been -read till the end. -#[punch: should we mention file-pointer?] +Now, let us learn to read the file line-by-line. But, before that we +will have to close the file, since the file has already been read till +the end. + +.. #[punch: should we mention file-pointer?] Let us close the file opened into f. :: @@ -89,8 +115,11 @@ Let us, now move on to reading files line-by-line. -%%1%% Pause the video here and re-open the file ``pendulum.txt`` -with ``f`` as the file object, and then resume the video. +Following is an exercise that you must do. + +%%2%% Re-open the file ``pendulum.txt`` with ``f`` as the file object. + +Please, pause the video here. Do the exercise and then continue. We just use the up arrow until we reach the open command and issue it again. @@ -123,8 +152,10 @@ statement. This will save us the trouble of closing the file, each time we open it. -for line in open('/home/fossee/pendulum.txt'): -line_list.append(line) +:: + + for line in open('/home/fossee/pendulum.txt'): + line_list.append(line) Let us see what ``line_list`` contains. :: @@ -143,5 +174,11 @@ a whole, using the read command or reading it line by line by iterating over the file object. -Thank you! +{{{ Show the "sponsored by FOSSEE" slide }}} + +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India +Hope you have enjoyed and found it useful. +Thank you! + + diff -r c507e9c413c6 -r 0ff3f1a97068 getting-started-ipython/questions.rst --- a/getting-started-ipython/questions.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/getting-started-ipython/questions.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,17 +1,17 @@ -Objective ---------- +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. ``ipython`` is a programming language similar to Python. T or F? -.. A mininum of 8 questions here. +#. + + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) 1. Question 1 2. Question 2 -3. Question 3 - - -Programming ------------ - -.. A minimum of 2 questions here. - -1. Programming Assignment 1 -2. Programming Assignment 2 diff -r c507e9c413c6 -r 0ff3f1a97068 getting-started-ipython/script.rst --- a/getting-started-ipython/script.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/getting-started-ipython/script.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,14 +1,19 @@ .. Objectives .. ---------- -.. Clearly state the objectives of the LO (along with RBT level) +.. At the end of this tutorial, you will be able to + +.. 1. invoke the ``ipython`` interpreter. +.. #. quit the ``ipython`` interpreter. +.. #. navigate in the history of ``ipython``. +.. #. use tab-completion. +.. #. look-up documentation of functions. +.. #. interrupt incomplete or incorrect commands. .. Prerequisites .. ------------- -.. 1. Name of LO-1 -.. 2. Name of LO-2 -.. 3. Name of LO-3 +.. should have ``ipython`` and ``pylab`` installed. .. Author : Puneeth Internal Reviewer : @@ -24,14 +29,14 @@ Hello Friends and Welcome to the tutorial on getting started with ``ipython``. -{{{ Show slide with outline of the session. }}} +{{{ Show slide with outline }}} This tutorial will cover the basic usage of the ``ipython`` interpreter. The following topics would be covered. IPython is an enhanced Python interpreter that provides features like -tabcompletion, easier access to help and many other functionalities -which are not available in the vannila Python interpreter. +tabcompletion, easier access to help and lot of other functionality +which are not available in the vanilla Python interpreter. First let us see how to invoke the ``ipython`` interpreter. @@ -98,8 +103,12 @@ tab. IPython does not complete the command since there are many possibilities. It just lists out all the possible completions. -%% %% Pause the video here and type ``ab`` and hit tab to see what -happens. Next, jut type ``a`` and hit tab to see what happens. +Following is an exercise that you must do. + +%%1%% Type ``ab`` and hit tab to see what happens. Next, jut type +``a`` and hit tab to see what happens. + +Please, pause the video here. Do the exercise and then continue. ``ab`` tab completes to ``abs`` and ``a`` gives us a list of all the commands starting with a. @@ -125,11 +134,11 @@ Does it work for decimals (or floats)? Let's try typing abs(-10.5) and we do get back 10.5. -Following is an (are) exercise(s) that you must do. +Following is an exercise that you must do. -%%1%% Look-up the documentation of ``round`` and see how to use it. +%%2%% Look-up the documentation of ``round`` and see how to use it. -Please, pause the video here. Do the exercises and then continue. +Please, pause the video here. Do the exercise and then continue. :: @@ -142,17 +151,20 @@ The function ``round``, rounds a number to a given precision. -%% %% Pause the video here and check the output of -round(2.48) -round(2.48, 1) -round(2.48, 2) -and then resume the video. +Following are exercises that you must do. + +%%3%% Check the output of:: -:: + round(2.48) + round(2.48, 1) + round(2.48, 2) + round(2.484) round(2.484, 1) round(2.484, 2) +Please, pause the video here. Do the exercises and then continue. + We get 2.0, 2.5 and 2.48, which are what we expect. Let's now see how to correct typing errors that we make when typing at @@ -174,7 +186,7 @@ Following is an exercise that you must do. -%%2%% Try typing round(2.484, and hit enter. and then cancel the +%%4%% Try typing round(2.484, and hit enter. and then cancel the command using Ctrl-C. Then, type the command, round(2.484, 2) and resume the video. @@ -193,7 +205,6 @@ In this tutorial we have learnt {{{ show the outline/summary slide. }}} - {{{ Show the "sponsored by FOSSEE" slide }}} This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India diff -r c507e9c413c6 -r 0ff3f1a97068 loading-data-from-files/pendulum.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/pendulum.txt Fri Oct 08 11:32:09 2010 +0530 @@ -0,0 +1,90 @@ +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 diff -r c507e9c413c6 -r 0ff3f1a97068 loading-data-from-files/pendulum_semicolon.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/pendulum_semicolon.txt Fri Oct 08 11:32:09 2010 +0530 @@ -0,0 +1,90 @@ +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 diff -r c507e9c413c6 -r 0ff3f1a97068 loading-data-from-files/primes.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/primes.txt Fri Oct 08 11:32:09 2010 +0530 @@ -0,0 +1,25 @@ +2 +3 +5 +7 +11 +13 +17 +19 +23 +29 +31 +37 +41 +43 +47 +53 +59 +61 +67 +71 +73 +79 +83 +89 +97 diff -r c507e9c413c6 -r 0ff3f1a97068 loading-data-from-files/questions.rst --- a/loading-data-from-files/questions.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/loading-data-from-files/questions.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,17 +1,63 @@ -Objective ---------- +Objective Questions +------------------- .. A mininum of 8 questions here. -1. Question 1 -2. Question 2 -3. Question 3 +1. ``loadtxt`` can read data only from a file with one column + only. True or False? + + Answer: False + +#. To read a file with multiple columns, into separate simple + sequences, ``loadtxt`` is given the additional argument ______? + + Answer: ``unpack=True`` + +#. We have a file with two columns of data separated by one of the + following characters. Which of them doesn't require the delimiter + argument to be specified, when using ``loadtxt``. + + a. ; + #. , + #. : + #. [space] + + Answer: [space] + +#. Given a file ``data.txt`` with three columns of data separated by + spaces, read it into one complex sequence. + Answer: ``x = loadtxt("data.txt")`` -Programming ------------ +#. Given a file ``data.txt`` with three columns of data separated by + spaces, read it into 3 separate simple sequences. + + Answer: ``x = loadtxt("data.txt", unpack=True)`` + +#. Given a file ``data.txt`` with three columns of data separated by + ``:``, read it into one complex sequence. + + Answer: ``x = loadtxt("data.txt", delimiter=":")`` + +#. Given a file ``data.txt`` with three columns of data separated by + ":", read it into 3 separate simple sequences. + + Answer: ``x = loadtxt("data.txt", unpack=True, delimiter=":")`` + +#. To use the loadtxt command, each row should have the same number of + values, T or F ? + + Answer: True + +Larger Questions +---------------- .. A minimum of 2 questions here. -1. Programming Assignment 1 -2. Programming Assignment 2 +1. What will happen if one of the cells is empty? + +#. Read a column with text? + +#. Given a file with 3 columns of data but two different delimiters, + what do you think will happen? + diff -r c507e9c413c6 -r 0ff3f1a97068 loading-data-from-files/script.rst --- a/loading-data-from-files/script.rst Thu Oct 07 14:40:21 2010 +0530 +++ b/loading-data-from-files/script.rst Fri Oct 08 11:32:09 2010 +0530 @@ -1,8 +1,30 @@ -======== - Script -======== +.. Objectives +.. ---------- + +.. At the end of this tutorial, you will be able to + +.. + Read data from files, containing a single column of data using the +.. ``loadtxt`` command. +.. + Read multiple columns of data, separated by spaces or other +.. delimiters. + + +.. Prerequisites +.. ------------- -Welcome to this tutorial on loading data from files. +.. 1. getting started with ``ipython`` + +.. Author : + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + +{{{ Show the slide containing title }}} + +Hello Friends. Welcome to this tutorial on loading data from files. {{{ Screen shows welcome slide }}} @@ -59,15 +81,19 @@ Now, let us use the ``loadtxt`` command to read a file that contains two columns of data, ``pendulum.txt``. This file contains the length of the pendulum in the first column and the corresponding time period -in the second. +in the second. Note that ``loadtxt`` needs both the columns to have +equal number of rows. -%%1%% Pause the video here, and use the ``cat`` command to view the -contents of this file and then resume the video. +.. Following is an exercise that you must do. + +.. %%1%% Use the ``cat`` command to view the contents of this file. -This is how we look at the contents of the file, ``pendulum.txt`` -:: +.. Please, pause the video here. Do the exercise and then continue. - cat /home/fossee/pendulum.txt +.. This is how we look at the contents of the file, ``pendulum.txt`` +.. :: + +.. cat /home/fossee/pendulum.txt .. #[Nishanth]: The first column is L values and second is T values from a simle pelculum experiment. @@ -114,13 +140,14 @@ In this tutorial, we have learnt the basic use of the ``loadtxt`` command, which is capable of doing a lot more than we have used it for -until now, for example +until now. Let us look at an example, but before that do this +exercise. -%%2%% Pause the video here, and read the file -``pendulum_semicolon.txt`` which contains the same data as -``pendulum.txt``, but the columns are separated by semi-colons instead -of spaces. Use the IPython help to see how to do this. Once you have -finished, resume the video to look at the solution. +%%1%% Read the file ``pendulum_semicolon.txt`` which contains the same +data as ``pendulum.txt``, but the columns are separated by semi-colons +instead of spaces. Use the IPython help to see how to do this. + +Please, pause the video here. Do the exercise and then continue. {{{ switch back to the terminal }}} :: @@ -142,5 +169,10 @@ + Read multiple columns of data, separated by spaces or other delimiters. -Thank you! +{{{ Show the "sponsored by FOSSEE" slide }}} + +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India +Hope you have enjoyed and found it useful. +Thank you! +