张量流中的外积 [英] Outer product in tensorflow

查看:42
本文介绍了张量流中的外积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在张量流中,有很好的入口和矩阵乘法函数,但在查看文档后,我找不到任何用于取两个张量的外积的内部函数,即,制作更大的张量由较小张量元素的所有可能乘积(如 numpy.outer):

In tensorflow, there are nice functions for entrywise and matrix multiplication, but after looking through the docs, I cannot find any internal function for taking an outer product of two tensors, i.e., making a bigger tensor by all possible products of elements of smaller tensors (like numpy.outer):

v_{i,j} = x_i*h_j

M_{ij,kl} = A_{ij}*B_{kl}

tensorflow有这样的功能吗?

Does tensorflow have such a function?

推荐答案

是的,您可以利用 tensorflow 的广播语义来做到这一点.将第一个大小调整为自身的 1xN 大小,将第二个大小调整为自身的 Mx1 大小,当您将它们相乘时,您将得到所有结果的广播.

Yes, you can do this by taking advantage of the broadcast semantics of tensorflow. Size the first out to size 1xN of itself, and the second to size Mx1 of itself, and you'll get a broadcast to MxN of all of the results when you multiply them.

(你可以在 numpy 中玩同样的东西,看看它在更简单的上下文中的表现,顺便说一句:

(You can play around with the same thing in numpy to see how it behaves in a simpler context, btw:

a = np.array([1, 2, 3, 4, 5]).reshape([5,1])
b = np.array([6, 7, 8, 9, 10]).reshape([1,5])
a*b

您在 tensorflow 中的具体操作方式在某种程度上取决于您要使用的轴以及结果乘法所需的语义,但总体思路适用.

How exactly you do it in tensorflow depends a bit on which axes you want to use and what semantics you want for the resulting multiply, but the general idea applies.

这篇关于张量流中的外积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆