# HG changeset patch # User Nishanth # Date 1285223076 -19800 # Node ID 3a839dca2bdb22728b2561b425cfe7e0436f989e # Parent 08b2cb94c57c0f6730af3bb603a83b6fa746b936 reviewed loading_data_from_files diff -r 08b2cb94c57c -r 3a839dca2bdb loading-data-from-files.rst --- a/loading-data-from-files.rst Thu Sep 23 11:00:44 2010 +0530 +++ b/loading-data-from-files.rst Thu Sep 23 11:54:36 2010 +0530 @@ -12,8 +12,10 @@ what we do most often. We often require to plot points obtained from experimental observations. -#[punch: the initial part of the paragraph may be removed, to make -this a more generic LO?] +.. #[punch: the initial part of the paragraph may be removed, to make + this a more generic LO?] + +.. #[Nishanth]: The paragraph can be removed. In this tutorial we shall learn to read data from files and save it into sequences that can later be used to plot. @@ -24,6 +26,9 @@ be looking at how to get multiple columns of data into multiple sequences. +.. #[Nishanth]: can be "How to read a file with multiple columns of + data and load each column of data into a sequence." + {{{ switch back to the terminal }}} As usual, let us start IPython, using @@ -35,7 +40,7 @@ just a list of primes listed in a column, using the loadtxt command. The file, in our case, is present in ``/home/fossee/primes.txt``. -#[punch: do we need a slide for showing the path?] +.. #[punch: do we need a slide for showing the path?] We use the ``cat`` command to see the contents of this file. @@ -44,6 +49,10 @@ cat /home/fossee/primes.txt +.. #[Nishanth]: A problem for windows users. + Should we simply open the file and show them the data + so that we can be fine with GNU/Linux ;) and windows? + Now let us read this list into the variable ``primes``. :: @@ -71,6 +80,12 @@ cat /home/fossee/pendulum.txt +.. #[Nishanth]: The first column is L values and second is T values + from a simle pelculum experiment. + Since you are using the variable names later in the + script. + Not necessary but can be included also. + Let us, now, read the data into the variable ``pend``. Again, it is assumed that the file is in ``/home/fossee/`` :: @@ -90,12 +105,17 @@ L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True) +.. #[Nishanth]: It has a sequence of items in which each item contains + two values. first is l and second is t + Let us now, print the variables L and T, to see what they contain. :: print L print T +.. #[Nishanth]: Stress on ``unpack=True`` ?? + Notice, that L and T now contain the first and second columns of data from the data file, ``pendulum.txt``, and they are both simple sequences. @@ -115,12 +135,14 @@ {{{ switch back to the terminal }}} :: - L, T = loadtxt('/home/fossee/pendulum.txt', unpack``True, delimiter``';') + L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True, delimiter=';') print L print T +.. #[Nishanth]: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', ...) + This brings us to the end of this tutorial. {{{ show the summary slide }}} diff -r 08b2cb94c57c -r 3a839dca2bdb progress.org --- a/progress.org Thu Sep 23 11:00:44 2010 +0530 +++ b/progress.org Thu Sep 23 11:54:36 2010 +0530 @@ -8,7 +8,7 @@ | 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | Madhu (Pending) | | 1.8 LO: | module level assessment | 3 | Madhu | | | |---------+----------------------------------------+-------+----------+---------------------+---------------------| -| 2.2 LO: | loading data from files | 3 | Punch | | | +| 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | Anoop (Pending) | | 2.3 LO: | plotting the data | 3 | Amit | Anoop (Pending) | Punch (Pending) | | 2.4 LO: | other types of plots | 3 | Anoop | | | | 2.5 LO: | module level assessment | 3 | Nishanth | | |