Difference between np.dot and np.multiply with np.sum in binary cross-entropy loss calculation

前端 未结 4 625
盖世英雄少女心
盖世英雄少女心 2021-01-30 22:09

I have tried the following code but didn\'t find the difference between np.dot and np.multiply with np.sum

Here is np.dot

4条回答
  •  春和景丽
    2021-01-30 22:42

    np.dot is the dot product of two matrices.

    |A B| . |E F| = |A*E+B*G A*F+B*H|
    |C D|   |G H|   |C*E+D*G C*F+D*H|
    

    Whereas np.multiply does an element-wise multiplication of two matrices.

    |A B| ⊙ |E F| = |A*E B*F|
    |C D|   |G H|   |C*G D*H|
    

    When used with np.sum, the result being equal is merely a coincidence.

    >>> np.dot([[1,2], [3,4]], [[1,2], [2,3]])
    array([[ 5,  8],
           [11, 18]])
    >>> np.multiply([[1,2], [3,4]], [[1,2], [2,3]])
    array([[ 1,  4],
           [ 6, 12]])
    
    >>> np.sum(np.dot([[1,2], [3,4]], [[1,2], [2,3]]))
    42
    >>> np.sum(np.multiply([[1,2], [3,4]], [[1,2], [2,3]]))
    23
    

提交回复
热议问题