lstsq/questions.rst
author Nishanth <nishanth@fossee.in>
Tue, 12 Oct 2010 11:44:33 +0530
changeset 335 d5248a15274c
parent 330 efb8ddf26aff
permissions -rw-r--r--
Finished writing_python_scripts

Objective Questions
-------------------

 1. What does ones_like([1, 2, 3]) produce

   a. array([1, 1, 1])
   #. [1, 1, 1]
   #. [1.0, 1.0, 1.0]
   #. Error
   
   Answer: array([1, 1, 1])
   
 2. What does ones_like([1.2, 3, 4, 5]) produce

   a. [1.2, 3, 4, 5]
   #. array([1.0, 1.0, 1.0, 1.0])
   #. array([1, 1, 1, 1])
   #. array([1.2, 3, 4, 5])

   Answer: array([1.0, 1.0, 1.0, 1.0])

 3. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
    linear trend. How do you find the least square fit line of ``u`` vs ``v``.

   Answer::

      A = array(u, ones_like(u)).T
      result = lstsq(A, v)
      m, c = result[0]

      lst_line = m * u + c