
上QQ阅读APP看书,第一时间看更新
Vectors
The Norm function is used to get the size of the vector; the norm of a vector x measures the distance from the origin to the point x. It is also known as the norm, where p=2 is known as the Euclidean norm.
The following example shows you how to calculate the norm of a given vector:
import tensorflow as tf
vector = tf.constant([[4,5,6]], dtype=tf.float32)
eucNorm = tf.norm(vector, ord="euclidean")
with tf.Session() as sess:
print(sess.run(eucNorm))
The output of the listing is 8.77496.