Python爬虫笔记-tf.matmul函数VS tf.multiply函数

matmul函数

matmul函数必须维度相符 32 24 = 3*4

a = np.array([[1,1],[2,2],[]3,3]) #维度为3*2
b = np.array([[1,1,1,1],[2,2,2,2]]) #维度为2*4
tf.matmul(a,b)  #3*4

multiply函数

multiply函数是两个矩阵对应的元素相乘,返回的是维度最多的矩阵格式

a1= np.array([[1,2],  
              [2,3],
              [3,4]])    #shape is 3*2 
b1 = np.array([2,3])     #shape is 1*2 

tf.multiply(a1,b1)       #shape is 3*2 
# output is: 
array([[ 2,  6],
       [ 4,  9],
       [ 6, 12]])

猜你喜欢

转载自blog.csdn.net/Jiana_Feng/article/details/109408001