Avijit Dasgupta
Avijit Dasgupta

Reputation: 2065

Mean Euclidean distance in Tensorflow

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

Answers (2)

AliPrf
AliPrf

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

nessuno
nessuno

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:

l2_norm = tf.norm(A-B, ord='euclidean')

Upvotes: 15

Related Questions