r"""Computes the norm of vectors, matrices, and tensors. This function can compute several different vector norms (the 1-norm, the Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and matrix norms (Frobenius, 1-norm, 2-norm and inf-norm). Args: tensor: `Tensor` o
(tensor,
ord='euclidean',
axis=None,
keepdims=None,
name=None,
keep_dims=None)
| 498 | @deprecation.deprecated_args( |
| 499 | None, 'keep_dims is deprecated, use keepdims instead', 'keep_dims') |
| 500 | def norm(tensor, |
| 501 | ord='euclidean', |
| 502 | axis=None, |
| 503 | keepdims=None, |
| 504 | name=None, |
| 505 | keep_dims=None): |
| 506 | r"""Computes the norm of vectors, matrices, and tensors. |
| 507 | |
| 508 | This function can compute several different vector norms (the 1-norm, the |
| 509 | Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) and |
| 510 | matrix norms (Frobenius, 1-norm, 2-norm and inf-norm). |
| 511 | |
| 512 | Args: |
| 513 | tensor: `Tensor` of types `float32`, `float64`, `complex64`, `complex128` |
| 514 | ord: Order of the norm. Supported values are 'fro', 'euclidean', |
| 515 | `1`, `2`, `np.inf` and any positive real number yielding the corresponding |
| 516 | p-norm. Default is 'euclidean' which is equivalent to Frobenius norm if |
| 517 | `tensor` is a matrix and equivalent to 2-norm for vectors. |
| 518 | Some restrictions apply: |
| 519 | a) The Frobenius norm `fro` is not defined for vectors, |
| 520 | b) If axis is a 2-tuple (matrix norm), only 'euclidean', 'fro', `1`, |
| 521 | `2`, `np.inf` are supported. |
| 522 | See the description of `axis` on how to compute norms for a batch of |
| 523 | vectors or matrices stored in a tensor. |
| 524 | axis: If `axis` is `None` (the default), the input is considered a vector |
| 525 | and a single vector norm is computed over the entire set of values in the |
| 526 | tensor, i.e. `norm(tensor, ord=ord)` is equivalent to |
| 527 | `norm(reshape(tensor, [-1]), ord=ord)`. |
| 528 | If `axis` is a Python integer, the input is considered a batch of vectors, |
| 529 | and `axis` determines the axis in `tensor` over which to compute vector |
| 530 | norms. |
| 531 | If `axis` is a 2-tuple of Python integers it is considered a batch of |
| 532 | matrices and `axis` determines the axes in `tensor` over which to compute |
| 533 | a matrix norm. |
| 534 | Negative indices are supported. Example: If you are passing a tensor that |
| 535 | can be either a matrix or a batch of matrices at runtime, pass |
| 536 | `axis=[-2,-1]` instead of `axis=None` to make sure that matrix norms are |
| 537 | computed. |
| 538 | keepdims: If True, the axis indicated in `axis` are kept with size 1. |
| 539 | Otherwise, the dimensions in `axis` are removed from the output shape. |
| 540 | name: The name of the op. |
| 541 | keep_dims: Deprecated alias for `keepdims`. |
| 542 | |
| 543 | Returns: |
| 544 | output: A `Tensor` of the same type as tensor, containing the vector or |
| 545 | matrix norms. If `keepdims` is True then the rank of output is equal to |
| 546 | the rank of `tensor`. Otherwise, if `axis` is none the output is a scalar, |
| 547 | if `axis` is an integer, the rank of `output` is one less than the rank |
| 548 | of `tensor`, if `axis` is a 2-tuple the rank of `output` is two less |
| 549 | than the rank of `tensor`. |
| 550 | |
| 551 | Raises: |
| 552 | ValueError: If `ord` or `axis` is invalid. |
| 553 | |
| 554 | @compatibility(numpy) |
| 555 | Mostly equivalent to numpy.linalg.norm. |
| 556 | Not supported: ord <= 0, 2-norm for matrices, nuclear norm. |
| 557 | Other differences: |