matrices/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 19 Oct 2010 14:26:02 +0530
changeset 337 c65d0d9fc0c8
parent 287 d9507624eb8f
child 397 4aea9ed09983
permissions -rw-r--r--
Reviewed Basic datatypes LO.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
     1
Objective Questions
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
     2
-------------------
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
     3
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
     4
.. A mininum of 8 questions here (along with answers)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
     5
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
     6
1. ``matrix(A) * matrix(B)`` and ``array(A) * array(B)`` are the same.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
     7
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
     8
    a. True
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
     9
    #. False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    10
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    11
Answer: False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    12
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    13
2. ``matrix(A) * array(B)`` does,
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    14
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    15
   a. Element wise multiplication.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    16
   #. Matrix multiplication.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    17
   #. Cannot multiply a matrix object and array object.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    18
   #. Depends on the shape of A and B, if compatible matrix
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    19
      multiplication will be done, otherwise element wise
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    20
      multiplication.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    21
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    22
Answer: Matrix multiplication
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    23
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    24
3. A and B are two matrix objects. Element wise multiplication in
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    25
   matrices are done by,
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    26
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    27
   a. A * B
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    28
   #. ``multiply(A, B)``
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    29
   #. ``dot(A, B)``
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    30
   #. ``element_multiply(A,B)``
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    31
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    32
Answer: multiply(A, B)
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    33
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    34
4. ``norm(A)`` method determines the,
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    35
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    36
   a. Frobenius norm
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    37
   #. Infinity norm
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    38
   #. Induced norm
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    39
   #. Schatten norm
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    40
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    41
Answer: Frobenius norm
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    42
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    43
5. ``eig(A)[1]`` and ``eigvals(A)`` are the same.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    44
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    45
   a. True
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    46
   #. False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    47
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    48
Answer: False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    49
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    50
6. The code snippet will work without an error,
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    51
   ::
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    52
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    53
       A = matrix([[1, 2, 3, 4], [5, 6, 7, 8]])
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    54
       inv(A)
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    55
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    56
   a. True
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    57
   #. False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    58
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    59
Answer: False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    60
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    61
7. What is the output of the following code,
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    62
   ::
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    63
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    64
      x = matrix([[1, 2, 3], ['a', 2, 'c']])
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    65
      identity(x.shape)
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    66
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    67
   a. Will create an identity matrix of shape (2, 3).
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    68
   #. ``identity()`` function takes an integer as argument and a tuple
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    69
      is passed.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    70
   #. Will return, matrix([[1,0,1],[0,1,0]])
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    71
   #. Will return, matrix([[0,1,0],[0,1,0]])
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    72
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    73
Answer: ``identity()`` function takes an integer as argument and a
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    74
      	tuple is passed.
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    75
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    76
8. ``norm(A,ord='fro')`` is the same as ``norm(A)``
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    77
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    78
   a. True
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    79
   #. False
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    80
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
    81
Answer: True
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    82
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    83
Larger Questions
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    84
----------------
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    85
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    86
.. A minimum of 2 questions here (along with answers)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    87
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    88
1. Consider an array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].  A fold and add
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    89
   operation consist of two phases, a right fold and add and a left
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    90
   fold and add.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    91
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    92
   Say in first fold and add, we take the right fold of the array and
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    93
   add it to the left like,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    94
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    95
   [1+10, 2+9, 3+8, 4+7, 5+6, 6, 7, 8, 9, 10]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    96
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    97
   and it becomes
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    98
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    99
   [11, 11, 11, 11, 11, 6, 7, 8, 9, 10]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   100
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   101
   and in the second fold and add, we take the left fold of the new
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   102
   array and add it to the right and it becomes,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   103
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   104
   [11, 11, 11, 11, 11, 17, 18, 19, 20, 21].
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   105
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   106
   What will be the array after 22 such operations starting with [1,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   107
   2, 3, 4, 5, 6, 7, 8, 9, 10]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   108
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   109
2. Find the infinity norm and the determinant of the inverse of the
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   110
   product of matrices A and B. 
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   111
   ::
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   112
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   113
      A = [[ 1,  2,  3,  4],     B = [[16, 15, 14, 13],
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   114
      	   [ 5,  6,  7,  8],          [12, 11, 10,  9],
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   115
	   [ 9, 10, 11, 12],          [ 8,  7,  6,  5],
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   116
	   [13, 14, 15, 16]]          [ 4,  3,  2,  1]]