Reputation: 2065
I have two tensors of sequences of size [batch_size, seq_length, 2]. I want to compute mean Euclidean distance between tensors. What is the elegant way to do this?
Upvotes: 15
Views: 13188
Reputation: 389
You can also use tf.math.reduce_euclidean_norm:
tf.math.reduce_euclidean_norm( input_tensor, axis=None, keepdims=False, name=None )
see the documentation here.
Upvotes: 1
Reputation: 27052
Given the two tensors A & B each with shape [batch_size, seq_length, 2], you can compute the Euclidean distance (L2 norm) using tf.norm:
A
B
[batch_size, seq_length, 2]
tf.norm
l2_norm = tf.norm(A-B, ord='euclidean')