np.dot()、np.multiply()、tf.matmul()、tf.multiply()

np.dot()、np.multiply()、tf.matmul()、tf.multiply()

import tensorflow as tf
import numpy as np

x1 = ([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
x2 = ([[2, 1, 1], [2, 1, 1], [2, 1, 1]])
y1 = np.dot(x1, x2)
y2 = np.multiply(x1, x2)
print('1、np.dot\n', y1)
print('2、np.multiply\n', y2)

x3 = tf.constant([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
x4 = tf.constant([[2, 1, 1], [2, 1, 1], [2, 1, 1]])
y3 = tf.matmul(x3, x4)
y4 = tf.multiply(x3, x4)

with tf.Session() as sess:
    print('3、tf.matmul\n',sess.run(y3))
    print('4、tf.multiply\n',sess.run(y4))
    print('5、np.dot\n',sess.run(np.dot(x3,x4)))
    print('6、np.multiply\n',sess.run(np.multiply(x3,x4)))

输出

1、np.dot
 [[12  6  6]
 [12  6  6]
 [12  6  6]]
2、np.multiply
 [[2 2 3]
 [2 2 3]
 [2 2 3]]
3、tf.matmul
 [[12  6  6]
 [12  6  6]
 [12  6  6]]
4、tf.multiply
 [[2 2 3]
 [2 2 3]
 [2 2 3]]
5、np.dot
 [[2 2 3]
 [2 2 3]
 [2 2 3]]
6、np.multiply
 [[2 2 3]
 [2 2 3]
 [2 2 3]]

1. tf.matmul() 为矩阵乘法
2. tf.multiply() 为矩阵点乘
3. np.dot() 为矩阵乘法
4. np.multiply()为矩阵点乘

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值