Differences between matrix multiplication and array point

I am new to Python. I have problems with matrix multiplication. I have two lists:

      A =[3.0,3.0]    
      # 1 by 2 matrix

      B =[[ 50.33112583, -49.66887417],
           [-49.66887417,  50.33112583]]
      # 2 by 2 matrix 

      Result should be :
      # 1 by 2 matrix
      c = [1.9867549668874176, 1.986754966887446] 


      Right now I am doing:
     >> A = numpy.matrix(A)
     >> B = numpy.matrix(B)

     >> C =A * B  
     >> C
        matrix([[ 1.98675497,  1.98675497]])

     >>C.tolist()
       [[1.9867549668874176, 1.986754966887446]]

If I make a point product, then

    >>> B =numpy.array(B)
    >>> B
    array([[ 50.33112583, -49.66887417],
   [-49.66887417,  50.33112583]])
    >>> A = [ 3.,  3.]
    >>> A =numpy.array(A)
    >>> A
      array([ 3.,  3.])
    >>> C = numpy.dot(A,B)
    >>> C
    array([ 1.98675497,  1.98675497])
    >>> C.tolist()
    [1.9867549668874176, 1.986754966887446]

Why do I get two brackets when I use matrix multiplication? Are point products and matrix multiplications the same? Can someone explain this to me?

+4
source share
1 answer

When you use it np.matrix(), it is by definition a two-dimensional container, and operations should be performed between 2-D objects and return 2-D objects:

np.matrix([[1,2,3], [4,5,6]])*[[1], [2], [3]]
#matrix([[14],
#        [32]])

np.matrix([[1,2,3], [4,5,6]])*[1, 2, 3]
#ValueError

np.array() dot() , 2-D ; 2-D 1-D 1-D :

np.array([[1,2,3], [4,5,6]]).dot([[1], [2], [3]])
#array([[14],
#       [32]])

np.array([[1,2,3], [4,5,6]]).dot([1, 2, 3])
#array([14, 32])

, . :

np.array([[1,2,3], [4,5,6]])*[[1], [2]]
#array([[ 1,  2,  3],
#       [ 8, 10, 12]])

:

np.array([[1,2,3], [4,5,6]])*[1, 2, 3]
#array([[ 1,  4,  9],
#       [ 4, 10, 18]])
+4

All Articles