张量流:更高维的元素减法

时间:2017-07-27 18:28:18

标签: tensorflow

我知道有一种方法可以像这样对张量进行元素运算。

// x is a 4d tensor
y = x - 1

但是,例如,如果将4d张量(MxNxVxW)减去1维(M)张量,则是相同的,使得对于(M)张量中的每个值,相应的(NxVxW)值被逐元素地减去?

1 个答案:

答案 0 :(得分:1)

是的,有可能,例如:

import tensorflow as tf
a=tf.constant([[[1,2,3],[4,5,6]],[[11,12,13],[14,15,16]]])
b=tf.constant([10,20,30])
res=a-b
sess=tf.InteractiveSession()
res.eval()

打印

array([[[ -9, -18, -27],
        [ -6, -15, -24]],

      [[  1,  -8, -17],
       [  4,  -5, -14]]])

相关问题