【发布时间】:2019-11-03 19:07:41
【问题描述】:
我需要分别获取张量每一行的外积。代码如下:
input1=K.placeholder(shape=(None, 12)) prod=K.map_fn(someMethod,input1)
someMethod 需要执行以下操作:
*def someMethod(x):*
## get the outerproduct row-wise of input1 #
outer=x*x.T
## subtract the identity matrix from the outer product #
diff=outer-np.eye(12)
## and return the trace of the difference matrix #
trace=np.trace(diff)
return trace
我希望跟踪值是标量,但 prod 是批量大小的输入列表?我使用 plaidml 作为后端,因此,希望与 numpy 或 keras 后端一起工作的东西,或者可能是 tensorflow。
【问题讨论】:
标签: python numpy tensorflow keras tensor