summaryrefslogtreecommitdiff
path: root/loading_data_from_files/script.rst
diff options
context:
space:
mode:
authorJovina2011-05-23 16:03:03 +0530
committerJovina2011-05-23 16:03:03 +0530
commitd3b14f3adda43847a11d26e6cda2cd65a291cc58 (patch)
treec7249384d95ba84b078a87fa8ec08dfde5d1aa28 /loading_data_from_files/script.rst
parent55dd6a16a1955e46487110e71305323335839e27 (diff)
downloadst-scripts-d3b14f3adda43847a11d26e6cda2cd65a291cc58.tar.gz
st-scripts-d3b14f3adda43847a11d26e6cda2cd65a291cc58.tar.bz2
st-scripts-d3b14f3adda43847a11d26e6cda2cd65a291cc58.zip
Modified scripts & slides in module 2.
Diffstat (limited to 'loading_data_from_files/script.rst')
-rw-r--r--loading_data_from_files/script.rst79
1 files changed, 46 insertions, 33 deletions
diff --git a/loading_data_from_files/script.rst b/loading_data_from_files/script.rst
index fd05ed3..b0d3245 100644
--- a/loading_data_from_files/script.rst
+++ b/loading_data_from_files/script.rst
@@ -30,7 +30,7 @@ team along with the logo of MHRD }}}
.. R1
-Hello Friends. Welcome to this tutorial on "loading data from files".
+Hello Friends and Welcome to this tutorial on "loading data from files".
.. L2
@@ -41,7 +41,8 @@ Hello Friends. Welcome to this tutorial on "loading data from files".
At the end of this tutorial, you will be able to,
1. Read data from files, containing a single column of data
- #. Read multiple columns of data, separated by spaces or other delimiters.
+ #. Read multiple columns of data, separated by spaces or other
+ delimiters.
.. L3
@@ -58,7 +59,8 @@ Let us switch to the terminal and start IPython, using ipython -pylab
Now, Let us begin with reading the file primes.txt, which contains
a list of prime numbers listed in a column, using the loadtxt command.
-Please make sure that you provide the correct path of the file 'primes.txt'.
+Please make sure that you provide the correct path of the file,
+'primes.txt'.
The file, in our case, is present in ``/home/fossee/primes.txt``.
.. L4
@@ -72,7 +74,8 @@ The file, in our case, is present in ``/home/fossee/primes.txt``.
.. R5
-Otherwise we can use the ``cat`` command to locate the file and read the contents of it.
+Otherwise we can use the ``cat`` command to locate the file and read the
+contents of it.
.. R6
@@ -85,8 +88,8 @@ Now let us read this list into the variable ``primes``.
.. R7
-``primes`` is now a sequence of prime numbers, that was listed in the file,
-``primes.txt``.
+``primes`` is now a sequence of prime numbers, that was listed in the
+file,``primes.txt``.
We now type, ``print primes`` to see the sequence printed.
@@ -106,11 +109,11 @@ because these numbers are actually read as ``floats``.
.. R9
-Now, let us use the ``loadtxt`` command to read a file ``pendulum.txt`` that contains
-two columns of data. This file contains the length
+Now, let us use the ``loadtxt`` command to read a file ``pendulum.txt``
+that contains two columns of data. This file contains the length
of the pendulum in the first column and the corresponding time period
-in the second. Note that here ``loadtxt`` needs both the columns to have
-equal number of rows.
+in the second. Note that here ``loadtxt`` needs both the columns to
+have equal number of rows.
We use the ``cat`` command to view the contents of this file.
@@ -170,6 +173,10 @@ separate sequences instead of one complex sequence.
.. L14
+.. L15
+
+{{{ Show slide with exercise 1 }}}
+
.. R15
Till now, we have learnt the basic use of the ``loadtxt``
@@ -181,35 +188,39 @@ 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.
-.. L15
+.. L16
{{{ switch back to the terminal }}}
::
- L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
+ L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True,
+ delimiter=';')
+
+ print L
- print L
+ print T
- print T
+.. R16
-.. L16
+.. L17
{{{ show the summary slide }}}
-.. R16
+.. R17
-This brings us to the end of this tutorial.
-let's revise quickly what we have learnt today.In this tutorial we learnt,
+This brings us to the end of this tutorial.In this tutorial,
+we have learnt to,
- 1. To Read data from files, containing a single column of data using the
- ``loadtxt`` command.
- #. To Read multiple columns of data, separated by spaces or other delimiters.
+ 1. To Read data from files, containing a single column of data
+ using the ``loadtxt`` command.
+ #. To Read multiple columns of data, separated by spaces or other
+ delimiters.
-.. L17
+.. L18
{{Show self assessment questions slide}}
-.. R17
+.. R18
1. ``loadtxt`` can read data from a file with one column
only. True or False?
@@ -221,35 +232,37 @@ let's revise quickly what we have learnt today.In this tutorial we learnt,
":", read it into 3 separate simple sequences.
-.. L18
+.. L19
{{{solution of self assessment questions on slide}}}
-.. R18
+.. R19
And the answers,
-1. False. ``loadtxt`` command can read data from files having both single columns as well as
- multiple columns.
+1. False. ``loadtxt`` command can read data from files having both single
+ columns as well as multiple columns.
-2. A file with three columns of data seperated by spaces to be read into 3 seperate sequences,
+2. A file with three columns of data seperated by spaces to be read into
+ 3 seperate sequences,
we use the loadtxt command as,
::
x = loadtxt("data.txt", unpack=True)
-3. If a file with three columns of data seperated by delimiters,we read it into three seperate sequences
- by using an additional argument of delimiter in the loadtxt command
+3. If a file with three columns of data seperated by delimiters,we read
+ it into three seperate sequences by using an additional argument of
+ delimiter in the loadtxt command
::
x = loadtxt("data.txt", unpack=True, delimiter=":")
-.. L19
+.. L20
{{{ Show the Thankyou slide }}}
-.. R19
+.. R20
-Hope you have enjoyed and found it useful.
+Hope you have enjoyed this tutorial and found it useful.
Thank you!