tf.math.reduce_euclidean_norm
Stay organized with collections
Save and categorize content based on your preferences.
Computes the Euclidean norm of elements across dimensions of a tensor.
tf.math.reduce_euclidean_norm(
input_tensor, axis=None, keepdims=False, name=None
)
Reduces input_tensor
along the dimensions given in axis
.
Unless keepdims
is true, the rank of the tensor is reduced by 1 for each
of the entries in axis
, which must be unique. If keepdims
is true, the
reduced dimensions are retained with length 1.
If axis
is None, all dimensions are reduced, and a
tensor with a single element is returned.
For example:
x = tf.constant([[1, 2, 3], [1, 1, 1]]) # x.dtype is tf.int32
tf.math.reduce_euclidean_norm(x) # returns 4 as dtype is tf.int32
y = tf.constant([[1, 2, 3], [1, 1, 1]], dtype = tf.float32)
tf.math.reduce_euclidean_norm(y) # returns 4.1231055 which is sqrt(17)
tf.math.reduce_euclidean_norm(y, 0) # [sqrt(2), sqrt(5), sqrt(10)]
tf.math.reduce_euclidean_norm(y, 1) # [sqrt(14), sqrt(3)]
tf.math.reduce_euclidean_norm(y, 1, keepdims=True) # [[sqrt(14)], [sqrt(3)]]
tf.math.reduce_euclidean_norm(y, [0, 1]) # sqrt(17)
Args |
input_tensor
|
The tensor to reduce. Should have numeric type.
|
axis
|
The dimensions to reduce. If None (the default), reduces all
dimensions. Must be in the range [-rank(input_tensor),
rank(input_tensor)) .
|
keepdims
|
If true, retains reduced dimensions with length 1.
|
name
|
A name for the operation (optional).
|
Returns |
The reduced tensor, of the same dtype as the input_tensor.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.reduce_euclidean_norm\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L2224-L2266) |\n\nComputes the Euclidean norm of elements across dimensions of a tensor. \n\n tf.math.reduce_euclidean_norm(\n input_tensor, axis=None, keepdims=False, name=None\n )\n\nReduces `input_tensor` along the dimensions given in `axis`.\nUnless `keepdims` is true, the rank of the tensor is reduced by 1 for each\nof the entries in `axis`, which must be unique. If `keepdims` is true, the\nreduced dimensions are retained with length 1.\n\nIf `axis` is None, all dimensions are reduced, and a\ntensor with a single element is returned.\n\n#### For example:\n\n x = tf.constant([[1, 2, 3], [1, 1, 1]]) # x.dtype is tf.int32\n tf.math.reduce_euclidean_norm(x) # returns 4 as dtype is tf.int32\n y = tf.constant([[1, 2, 3], [1, 1, 1]], dtype = tf.float32)\n tf.math.reduce_euclidean_norm(y) # returns 4.1231055 which is sqrt(17)\n tf.math.reduce_euclidean_norm(y, 0) # [sqrt(2), sqrt(5), sqrt(10)]\n tf.math.reduce_euclidean_norm(y, 1) # [sqrt(14), sqrt(3)]\n tf.math.reduce_euclidean_norm(y, 1, keepdims=True) # [[sqrt(14)], [sqrt(3)]]\n tf.math.reduce_euclidean_norm(y, [0, 1]) # sqrt(17)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_tensor` | The tensor to reduce. Should have numeric type. |\n| `axis` | The dimensions to reduce. If `None` (the default), reduces all dimensions. Must be in the range `[-rank(input_tensor), rank(input_tensor))`. |\n| `keepdims` | If true, retains reduced dimensions with length 1. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The reduced tensor, of the same dtype as the input_tensor. ||\n\n\u003cbr /\u003e"]]