tf.norm . (tf version == 1.4 .)
:
import tensorflow as tf
a = tf.random_uniform((3, 4))
b = tf.norm(a, keep_dims=True)
c = tf.norm(a, axis=1, keep_dims=True)
d = a / c
e = a / tf.sqrt(tf.reduce_sum(tf.square(a), axis=1, keep_dims=True) + 1e-8)
f = a / tf.sqrt(tf.reduce_sum(tf.square(a), axis=1, keep_dims=True))
g = tf.sqrt(tf.reduce_sum(tf.square(a), axis=1, keep_dims=True))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
a_eval, b_eval, c_eval, d_eval, e_eval, f_eval, g_eval = sess.run([a, b, c, d, e, f, g])
print(a_eval)
print(b_eval)
print(c_eval)
print(d_eval)
print(e_eval)
print(f_eval)
print(g_eval)
:
[[ 0.29823065 0.76523042 0.40478575 0.44568062]
[ 0.0222317 0.12344956 0.39582515 0.66143286]
[ 0.01351094 0.38285756 0.46898723 0.34417391]]
[[ 1.4601624]]
[[ 1.01833284]
[ 0.78096414]
[ 0.6965394 ]]
[[ 0.29286167 0.75145411 0.39749849 0.43765712]
[ 0.02846699 0.15807328 0.50684166 0.84694397]
[ 0.01939724 0.54965669 0.6733104 0.49411979]]
[[ 0.29286167 0.75145411 0.39749849 0.43765712]
[ 0.02846699 0.15807328 0.50684166 0.84694397]
[ 0.01939724 0.54965669 0.6733104 0.49411979]]
[[ 0.29286167 0.75145411 0.39749849 0.43765712]
[ 0.02846699 0.15807328 0.50684166 0.84694397]
[ 0.01939724 0.54965669 0.6733104 0.49411979]]
[[ 1.01833284]
[ 0.78096414]
[ 0.6965394 ]]
, a / tf.norm(a, axis=1, keep_dims=True) a / tf.sqrt(tf.reduce_sum(tf.square(a), axis=1, keep_dims=True) + 1e-8).
a / tf.sqrt(tf.reduce_sum(tf.square(a), axis=1, keep_dims=True) + 1e-8) , .