# HG changeset patch # User Puneeth Chaganti # Date 1286517661 -19800 # Node ID 4d8ef03627b58dbcaaf215154bc30095fbeab7ee # Parent cad8e64dcd829fb6f50432e3ca957c93374bb9a6 Added questions to loading data from files LO. diff -r cad8e64dcd82 -r 4d8ef03627b5 loading-data-from-files/questions.rst --- a/loading-data-from-files/questions.rst Fri Oct 08 11:30:31 2010 +0530 +++ b/loading-data-from-files/questions.rst Fri Oct 08 11:31:01 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 cad8e64dcd82 -r 4d8ef03627b5 loading-data-from-files/script.rst --- a/loading-data-from-files/script.rst Fri Oct 08 11:30:31 2010 +0530 +++ b/loading-data-from-files/script.rst Fri Oct 08 11:31:01 2010 +0530 @@ -81,7 +81,8 @@ 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. .. Following is an exercise that you must do. @@ -139,9 +140,8 @@ 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 - -Following is an exercise that you must do. +until now. Let us look at an example, but before that do this +exercise. %%1%% Read the file ``pendulum_semicolon.txt`` which contains the same data as ``pendulum.txt``, but the columns are separated by semi-colons