在Tensorflow中,我想从另一列中减去2D张量中的一列。我看过如何使用tf.split()或tf.slice()将两个张量拆分成两个张量,然后减去,但这似乎是不必要的复杂。我目前的方法是将一列乘以-1,然后reduce_sum列:
input = tf.constant(
[[5.8, 3.0],
[4.0, 6.0],
[7.0, 9.0]])
oneMinusOne = tf.constant([1., -1.])
temp = tf.mul(input, oneMinusOne)
delta = tf.reduce_sum(temp, 1)似乎仍然是不必要的复杂。有更简单的方法吗?
发布于 2017-01-17 00:37:21
许多numpy的数组索引工作与TensorFlow中预期的一样。以下工作如下:
input = tf.constant(
[[5.8, 3.0],
[4.0, 6.0],
[7.0, 9.0]])
sess = tf.InteractiveSession()
ans = input[:, :1] - input[:, 1:]
print(ans.eval())
array([[ 2.80000019],
[-2. ],
[-2. ]], dtype=float32)https://stackoverflow.com/questions/41686280
复制相似问题