1

enter image description here

How to get from A and B to C? A and B are tensors and belong to the output of the network. Now I need to get C from the output operation of the two networks, and then use C to calculate loss function.

The key problem is to optimize A and B by loss function in the later stage, so it must be completed in the form of computational graphs. The TensorFlow formulas for calculating tensors don't seem to be able to solve this problem.

2 Answers 2

2

Use tf.norm:

C = tf.norm(B - A, axis=-1)
Sign up to request clarification or add additional context in comments.

Comments

1
import tensorflow as tf

#Create The Tensors
pt_a = tf.constant([5., 10.,11.])
pt_b = tf.constant([8., 3.,12.])

#Print Euclidean Distance
print("Euclidean Distance:",tf.norm(pt_a-pt_b,ord='euclidean'))

2 Comments

Hi, welcome to SO. Consider adding an explanation of how your code answers the problem/question. Code-only answers are often less useful for people new to the language or topic.
Define the points as tensor constants and use the tensor norm function to determine the euclidean distance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.