lstsq/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  1. What does ones_like([1, 2, 3]) produce
       
     5 
       
     6    a. array([1, 1, 1])
       
     7    #. [1, 1, 1]
       
     8    #. [1.0, 1.0, 1.0]
       
     9    #. Error
       
    10    
       
    11    Answer: array([1, 1, 1])
       
    12    
       
    13  2. What does ones_like([1.2, 3, 4, 5]) produce
       
    14 
       
    15    a. [1.2, 3, 4, 5]
       
    16    #. array([1.0, 1.0, 1.0, 1.0])
       
    17    #. array([1, 1, 1, 1])
       
    18    #. array([1.2, 3, 4, 5])
       
    19 
       
    20    Answer: array([1.0, 1.0, 1.0, 1.0])
       
    21 
       
    22  3. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
       
    23     linear trend. How do you find the least square fit line of ``u`` vs ``v``.
       
    24 
       
    25    Answer::
       
    26 
       
    27       A = array(u, ones_like(u)).T
       
    28       result = lstsq(A, v)
       
    29       m, c = result[0]
       
    30 
       
    31       lst_line = m * u + c
       
    32