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

前端 未结 4 560
盖世英雄少女心
盖世英雄少女心 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 23:00

    In this example it just not a coincidence. Lets take an example we have two (1,3) and (1,3) matrices. 
    // Lets code 
    
    import numpy as np
    
    x1=np.array([1, 2, 3]) // first array
    x2=np.array([3, 4, 3]) // second array
    
    //Then 
    
    X_Res=np.sum(np.multiply(x1,x2)) 
    // will result 20 as it will be calculated as - (1*3)+(2*4)+(3*3) , i.e element wise
    // multiplication followed by sum.
    
    Y_Res=np.dot(x1,x2.T) 
    
    // in order to get (1,1) matrix) from a dot of (1,3) matrix and //(1,3) matrix we need to //transpose second one. 
    //Hence|1 2 3| * |3|
    //               |4| = |1*3+2*4+3*3| = |20|
    //               |3|
    // will result 20 as it will be (1*3)+(2*4)+(3*3) , i.e. dot product of two matrices
    
    print X_Res //20
    
    print Y_Res //20
    

提交回复
热议问题