1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| arr = tf.range(-2, 4) t = tf.cast(tf.reshape(arr, [2, -1]), tf.float32)
t10 = tf.sqrt(tf.reduce_sum(tf.square(t))) t11 = tf.norm(t) t12 = tf.norm(t, ord=2)
t21 = tf.norm(t, ord=1)
t22 = tf.norm(t, ord=3)
t31 = tf.norm(t, axis=0)
t32 = tf.norm(t, axis=1)
t41 = tf.norm(t, ord=1, axis=0)
t42 = tf.norm(t, ord=3, axis=0)
print(t) print(t10) print(t11) print(t12) print(t21) print(t22) print(t31) print(t32) print(t41) print(t42)
|