Reputation: 93
Suppose I have one 4x3
matrix. I want to subtract every element in that matrix from each other.
I've looked around TensorFlow documentation extensively (and on SO) and noticed that there is a tf.subtract
operator. In adding, I know that there is tf.add_n
operator which adds all input tensors. I'm new to TensorFlow and was wondering: is there such a subtraction operator which subtracts all input tensors and if not, can you please provide an example of the fastest way to do so?
Example matrix tensor: [[0.10, 0.20], [0.20, 0.40]]
so expanded as:
0.10 0.20
0.20 0.40
Desired subtraction: 0.10 - 0.20 - 0.20 - 0.40
with desired output as: -.7
Upvotes: 0
Views: 261
Reputation: 1508
What you’re describing is the opposite of the sum, substituting the opposite of the first element of the first vector.
tf[0][0] = tf[0][0] * -1
And then use
tf.reduce_sum() * -1
Upvotes: 1