2024-04-24 02:47:38 发布
网友
假设我们有两个二维张量
A = [[a, b], [c, d]]和,B=[[e, f], [g, h]]
A = [[a, b], [c, d]]
B=[[e, f], [g, h]]
我需要一个值为[ae + bf + ce + df, ag + ah + cg + ch]的一维张量
[ae + bf + ce + df, ag + ah + cg + ch]
提前谢谢你的帮助
import tensorflow as tf A=[[1, 2], [3, 4]] B=[[5, 6], [7, 8]] Ax = tf.Variable(initial_value=A) Bx = tf.Variable(initial_value=B) with tf.Session() as sess : sess.run( tf.global_variables_initializer() ) ABx = tf.tensordot(Ax, Bx, axes=[[1], [1]]) print(sess.run( tf.reduce_sum(ABx, 0) ))
ABx = tf.tensordot(Ax, Bx, axes=[[1], [1]])给你这个。你知道吗
ABx = tf.tensordot(Ax, Bx, axes=[[1], [1]])
[[17 23] [39 53]]
tf.reduce_sum(ABx, 0)给你这个。你知道吗
tf.reduce_sum(ABx, 0)
[56 76]
代码tf.reduce_sum(tf.matmul(Ax, Bx,transpose_b=True),0)也给出了相同的结果。你知道吗
tf.reduce_sum(tf.matmul(Ax, Bx,transpose_b=True),0)
ABx = tf.tensordot(Ax, Bx, axes=[[1], [1]])
给你这个。你知道吗tf.reduce_sum(ABx, 0)
给你这个。你知道吗代码
tf.reduce_sum(tf.matmul(Ax, Bx,transpose_b=True),0)
也给出了相同的结果。你知道吗相关问题 更多 >
编程相关推荐