tf.multiply dot tf.matmul用法

import tensorflow as tf
a = tf.constant([[1,2,3],[1,2,3]])

b = tf.constant([[2,3,4]])

b_1 = tf.constant([[2,3],[1,2],[3,4]])
print("a",a)
print("b",b)
print("b_1",b_1)

c = a*b # (2,3)*(1,3)->(2,3) 两个矩阵中对应元素各自相乘
print("c",c)

d = tf.multiply(a,b)# (2,3)*(1,3)->(2,3) 两个矩阵中对应元素各自相乘
print("d",d)

e = tf.matmul(a,b_1)# 矩阵乘法(2,3)*(3,2)->(2,2)
print("e",e)
c = tf.Print(c,[c])

with tf.Session() as sess:
    print(sess.run(c))
    print(sess.run(d))
    print(sess.run(e))

output:

a Tensor("Const:0", shape=(2, 3), dtype=int32)
b Tensor("Const_1:0", shape=(1, 3), dtype=int32)
b_1 Tensor("Const_2:0", shape=(3, 2), dtype=int32)
c Tensor("mul:0", shape=(2, 3), dtype=int32)
d Tensor("Mul_1:0", shape=(2, 3), dtype=int32)
e Tensor("MatMul:0", shape=(2, 2), dtype=int32)
2018-10-22 13:46:41.956674: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
[[ 2  6 12]
 [ 2  6 12]]
[[2 6 12]...]
[[ 2  6 12]
 [ 2  6 12]]
[[13 19]
 [13 19]]

Process finished with exit code 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值