将两个具有不同形状的3D张量乘以(张量)
在TensorFlow中,如果我有两个3维张量,一个尺寸之一(100、9、135),另一个具有尺寸(100、29、135):
x1:tensor(shape =(100、9、135),dtype = float64)
x2:张量(shape =(100,29,135),dtype = float64)
我需要乘以这两个张量,因此当我使用“ tf.multiply”时,我会出现错误,如下所示:
z = tf.tf.multiplyly (x1,x2)
print(“ z:”,z)
值:尺寸必须相等,但为9和29,带有输入形状:[100,9,135],[100,29,135]。
如何在TensorFlow中完成?提前致谢。
In TensorFlow, If I have two 3 dimensional tensors, one of dimension (100, 9, 135) and the other has dimension (100, 29, 135):
x1: Tensor(shape=(100, 9, 135), dtype=float64)
x2: Tensor(shape=(100, 29, 135), dtype=float64)
I need to multiply these two tensors, so when I was using "tf.multiply" I got an error as follows:
z = tf.multiply(x1,x2)
print("z:", z)
ValueError: Dimensions must be equal, but are 9 and 29, with input shapes: [100,9,135], [100,29,135].
How can this be done in TensorFlow? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您期望的输出形状,但是您可以尝试使用
tf.einsum
进行矩阵乘法进行实验:检查 docs 有关更多选项。
I am not sure what output shape you expect, but you can try experimenting with
tf.einsum
to do matrix multiplication:Check the docs for more options.