Improve tf.math.l2_normalize documentation

PiperOrigin-RevId: 347916547
Change-Id: Id987582e673fc19320986aaa212ad49e6a100643
This commit is contained in:
Yanhua Sun 2020-12-16 16:08:00 -08:00 committed by TensorFlower Gardener
parent d7f7f61c76
commit 82b21e6ab7

View File

@ -646,6 +646,22 @@ def l2_normalize_v2(x, axis=None, epsilon=1e-12, name=None):
For `x` with more dimensions, independently normalizes each 1-D slice along
dimension `axis`.
* 1-D tensor example:
>>> x = tf.constant([3.0, 4.0])
>>> tf.math.l2_normalize(x).numpy()
array([0.6, 0.8], dtype=float32)
* 2-D tensor example:
>>> x = tf.constant([[3.0], [4.0]])
>>> tf.math.l2_normalize(x, 0).numpy()
array([[0.6],
[0.8]], dtype=float32)
>>> x = tf.constant([[3.0], [4.0]])
>>> tf.math.l2_normalize(x, 1).numpy()
array([[1.],
[1.]], dtype=float32)
Args:
x: A `Tensor`.
axis: Dimension along which to normalize. A scalar or a vector of