Python 行张量乘法

Python 行张量乘法,python,python-3.x,tensorflow,tensor,Python,Python 3.x,Tensorflow,Tensor,假设我们有两个二维张量 A=[[A,b],[c,d]]和,b=[[e,f],[g,h] 我需要一个具有值的一维张量[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 se

假设我们有两个二维张量

A=[[A,b],[c,d]]
和,
b=[[e,f],[g,h]

我需要一个具有值的一维张量
[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,axs=[[1],[1]])
给出了这一点

[[17 23]
 [39 53]]
[56 76]
tf.reduce\u sum(ABx,0)
给出了这一点

[[17 23]
 [39 53]]
[56 76]
代码
tf.reduce\u sum(tf.matmul(Ax,Bx,transpose\u b=True),0)
也给出了相同的结果。

查看逻辑。