loading-data-from-files/questions.rst
changeset 522 d33698326409
parent 521 88a01948450d
child 523 54bdda4aefa5
equal deleted inserted replaced
521:88a01948450d 522:d33698326409
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here. 
       
     5 
       
     6 1. ``loadtxt`` can read data only from a file with one column
       
     7    only. True or False?
       
     8 
       
     9    Answer: False
       
    10 
       
    11 #. To read a file with multiple columns, into separate simple
       
    12    sequences, ``loadtxt`` is given the additional argument ______?
       
    13 
       
    14    Answer: ``unpack=True``
       
    15 
       
    16 #. We have a file with two columns of data separated by one of the
       
    17    following characters. Which of them doesn't require the delimiter
       
    18    argument to be specified, when using ``loadtxt``. 
       
    19 
       
    20    a. ;
       
    21    #. , 
       
    22    #. :
       
    23    #. [space] 
       
    24    
       
    25    Answer: [space]
       
    26    
       
    27 #. Given a file ``data.txt`` with three columns of data separated by
       
    28    spaces, read it into one complex sequence. 
       
    29 
       
    30    Answer: ``x = loadtxt("data.txt")``
       
    31 
       
    32 #. Given a file ``data.txt`` with three columns of data separated by
       
    33    spaces, read it into 3 separate simple sequences. 
       
    34 
       
    35    Answer: ``x = loadtxt("data.txt", unpack=True)``
       
    36 
       
    37 #. Given a file ``data.txt`` with three columns of data separated by
       
    38    ``:``, read it into one complex sequence. 
       
    39 
       
    40    Answer: ``x = loadtxt("data.txt", delimiter=":")``
       
    41 
       
    42 #. Given a file ``data.txt`` with three columns of data separated by
       
    43    ":", read it into 3 separate simple sequences. 
       
    44 
       
    45    Answer: ``x = loadtxt("data.txt", unpack=True, delimiter=":")``
       
    46 
       
    47 #. To use the loadtxt command, each row should have the same number of
       
    48    values, T or F ?
       
    49 
       
    50    Answer: True
       
    51 
       
    52 Larger Questions
       
    53 ----------------
       
    54 
       
    55 .. A minimum of 2 questions here. 
       
    56 
       
    57 1. What will happen if one of the cells is empty?
       
    58 
       
    59 #. Given a file with 3 columns of data but two different delimiters,
       
    60    what do you think will happen?
       
    61 
       
    62 #. Read a column with text? 
       
    63 
       
    64 #. An input file contains 5 columns of data. Use only the second and fourth
       
    65    columns of data and load into two different variables.
       
    66    [hint: read the documentation, use the argument ``usecols``]
       
    67 .. #[bhanu: solutions are not seen to have been included.]