Tensorflow - Euclidean Distance of Points in Matrix
Define a function to calculate distances
calc_distance = lambda f, g: tf.norm(f-g, axis=1, ord='euclidean')
Pass your n*m vector to the function, example:
P = tf.constant([[1, 2], [3, 4], [2, 1], [0, 2], [2, 3]], dtype=tf.float32)
distances = calc_distance(P[:-1:], P[1::])
print(distances)
<tf.Tensor: shape=(4,), dtype=float32, numpy=array([2.8284273, 3.1622777, 2.2360682, 2.2360682], dtype=float32)>
I have a n*m tensor that basically represents m points in n dimensional euclidean space. I wanted calculate the pairwise euclidean distance between each consecutive point.
That is, if my column vectors are the points a, b, c, etc., I want to calculate euc(a, b), euc(b, c), etc.
The result would be an m-1 length 1D-tensor with each pairwise euclidean distance.
Anyone know who this can be performed in TensorFlow?