author | anand |
Sun, 07 Nov 2010 00:24:13 +0530 | |
changeset 386 | 003d185136ba |
parent 384 | 525ae0d74e47 |
permissions | -rw-r--r-- |
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
1 |
.. Objectives |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
2 |
.. ---------- |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
3 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
4 |
.. At the end of this tutorial, you will be able to |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
5 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
6 |
.. + Read data from files, containing a single column of data using the |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
7 |
.. ``loadtxt`` command. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
8 |
.. + Read multiple columns of data, separated by spaces or other |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
9 |
.. delimiters. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
10 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
11 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
12 |
.. Prerequisites |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
13 |
.. ------------- |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
|
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
15 |
.. 1. getting started with ``ipython`` |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
16 |
|
384 | 17 |
.. #[Anand: author and internal reviewer not mentioned] |
386 | 18 |
.. Author : Puneeth Changanti |
19 |
Internal Reviewer : Nishanth Amuluru |
|
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
20 |
External Reviewer : |
384 | 21 |
Language Reviewer : Bhanukiran |
386 | 22 |
Checklist OK? : <06-11-2010 Anand, OK> [2010-10-05] |
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
23 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
24 |
Script |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
25 |
------ |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
26 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
27 |
{{{ Show the slide containing title }}} |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
28 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
29 |
Hello Friends. Welcome to this tutorial on loading data from files. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
31 |
{{{ Screen shows welcome slide }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
We often require to plot points obtained from experimental |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
34 |
observations. In this tutorial we shall learn to read data from files |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
35 |
and save it into sequences that can later be used to plot. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
36 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
37 |
{{{ Show the outline for this tutorial }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
We shall use the ``loadtxt`` command to load data from files. We will |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
40 |
be looking at how to read a file with multiple columns of data and |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
load each column of data into a sequence. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
43 |
{{{ switch back to the terminal }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
44 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
45 |
As usual, let us start IPython, using |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
46 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
ipython -pylab |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
49 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
50 |
Now, Let us begin with reading the file primes.txt, which contains |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
51 |
just a list of primes listed in a column, using the loadtxt command. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
52 |
The file, in our case, is present in ``/home/fossee/primes.txt``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
53 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
54 |
{{{ Navigate to the path in the OS, open the file and show it }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
55 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
56 |
.. #[punch: do we need a slide for showing the path?] |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
58 |
.. We use the ``cat`` command to see the contents of this file. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
59 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
60 |
.. #[punch: should we show the cat command here? seems like a good place |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
61 |
to do it] :: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
62 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
63 |
cat /home/fossee/primes.txt |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
64 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
65 |
.. #[Nishanth]: A problem for windows users. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
66 |
Should we simply open the file and show them the data |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
67 |
so that we can be fine with GNU/Linux ;) and windows? |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
68 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
69 |
Now let us read this list into the variable ``primes``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
70 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
71 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
72 |
primes = loadtxt('/home/fossee/primes.txt') |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
73 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
74 |
``primes`` is now a sequence of primes, that was listed in the file, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
75 |
``primes.txt``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
76 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
77 |
We now type, ``print primes`` to see the sequence printed. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
78 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
We observe that all of the numbers end with a period. This is so, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
because these numbers are actually read as ``floats``. We shall learn |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
about them, later. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
Now, let us use the ``loadtxt`` command to read a file that contains |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
two columns of data, ``pendulum.txt``. This file contains the length |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
of the pendulum in the first column and the corresponding time period |
250
4d8ef03627b5
Added questions to loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
248
diff
changeset
|
86 |
in the second. Note that ``loadtxt`` needs both the columns to have |
4d8ef03627b5
Added questions to loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
248
diff
changeset
|
87 |
equal number of rows. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
|
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
89 |
.. Following is an exercise that you must do. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
90 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
91 |
.. %%1%% Use the ``cat`` command to view the contents of this file. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
92 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
93 |
.. Please, pause the video here. Do the exercise and then continue. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
94 |
|
248
0bad7228029c
Commented part of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
247
diff
changeset
|
95 |
.. This is how we look at the contents of the file, ``pendulum.txt`` |
0bad7228029c
Commented part of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
247
diff
changeset
|
96 |
.. :: |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
97 |
|
248
0bad7228029c
Commented part of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
247
diff
changeset
|
98 |
.. cat /home/fossee/pendulum.txt |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
99 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
100 |
.. #[Nishanth]: The first column is L values and second is T values |
384 | 101 |
from a simple pendulum experiment. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
102 |
Since you are using the variable names later in the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
103 |
script. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
104 |
Not necessary but can be included also. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
105 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
106 |
Let us, now, read the data into the variable ``pend``. Again, it is |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
107 |
assumed that the file is in ``/home/fossee/`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
108 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
109 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
110 |
pend = loadtxt('/home/fossee/pendulum.txt') |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
111 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
112 |
Let us now print the variable ``pend`` and see what's in it. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
113 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
114 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
115 |
print pend |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
116 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
117 |
Notice that ``pend`` is not a simple sequence like ``primes``. It has |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
118 |
two sequences, containing both the columns of the data file. Let us |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
119 |
use an additional argument of the ``loadtxt`` command, to read it into |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
120 |
two separate, simple sequences. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
121 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
122 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
123 |
L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
124 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
125 |
.. #[Nishanth]: It has a sequence of items in which each item contains |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
126 |
two values. first is l and second is t |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
127 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
128 |
Let us now, print the variables L and T, to see what they contain. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
129 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
130 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
131 |
print L |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
132 |
print T |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
133 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
134 |
.. #[Nishanth]: Stress on ``unpack=True`` ?? |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
135 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
136 |
Notice, that L and T now contain the first and second columns of data |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
137 |
from the data file, ``pendulum.txt``, and they are both simple |
384 | 138 |
sequences. ``unpack=True`` has given us the two columns into two |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
139 |
separate sequences instead of one complex sequence. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
140 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
141 |
{{{ show the slide with loadtxt --- other features }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
142 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
143 |
In this tutorial, we have learnt the basic use of the ``loadtxt`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
144 |
command, which is capable of doing a lot more than we have used it for |
250
4d8ef03627b5
Added questions to loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
248
diff
changeset
|
145 |
until now. Let us look at an example, but before that do this |
4d8ef03627b5
Added questions to loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
248
diff
changeset
|
146 |
exercise. |
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
147 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
148 |
%%1%% Read the file ``pendulum_semicolon.txt`` which contains the same |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
149 |
data as ``pendulum.txt``, but the columns are separated by semi-colons |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
150 |
instead of spaces. Use the IPython help to see how to do this. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
151 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
152 |
Please, pause the video here. Do the exercise and then continue. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
153 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
154 |
{{{ switch back to the terminal }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
155 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
156 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
157 |
L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
158 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
159 |
print L |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
160 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
161 |
print T |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
162 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
163 |
This brings us to the end of this tutorial. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
164 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
165 |
{{{ show the summary slide }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
166 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
167 |
You should now be able to do the following, comfortably. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
168 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
169 |
+ Read data from files, containing a single column of data using the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
170 |
``loadtxt`` command. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
171 |
+ Read multiple columns of data, separated by spaces or other |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
172 |
delimiters. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
173 |
|
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
174 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
175 |
|
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
176 |
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
177 |
|
247
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
178 |
Hope you have enjoyed and found it useful. |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
179 |
Thank you! |
81bb9a6d7eeb
Fixed script of loading data from files LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
180 |