Singular Value Decomposition. When `a` is a 2D array, and ``full_matrices=False``, then it is factorized as ``u @ np.diag(s) @ vh = (u * s) @ vh``, where `u` and the Hermitian transpose of `vh` are 2D arrays with orthonormal columns and `s` is a 1D array of `a`'s singular v
(a, full_matrices=True, compute_uv=True, hermitian=False)
| 1498 | |
| 1499 | @array_function_dispatch(_svd_dispatcher) |
| 1500 | def svd(a, full_matrices=True, compute_uv=True, hermitian=False): |
| 1501 | """ |
| 1502 | Singular Value Decomposition. |
| 1503 | |
| 1504 | When `a` is a 2D array, and ``full_matrices=False``, then it is |
| 1505 | factorized as ``u @ np.diag(s) @ vh = (u * s) @ vh``, where |
| 1506 | `u` and the Hermitian transpose of `vh` are 2D arrays with |
| 1507 | orthonormal columns and `s` is a 1D array of `a`'s singular |
| 1508 | values. When `a` is higher-dimensional, SVD is applied in |
| 1509 | stacked mode as explained below. |
| 1510 | |
| 1511 | Parameters |
| 1512 | ---------- |
| 1513 | a : (..., M, N) array_like |
| 1514 | A real or complex array with ``a.ndim >= 2``. |
| 1515 | full_matrices : bool, optional |
| 1516 | If True (default), `u` and `vh` have the shapes ``(..., M, M)`` and |
| 1517 | ``(..., N, N)``, respectively. Otherwise, the shapes are |
| 1518 | ``(..., M, K)`` and ``(..., K, N)``, respectively, where |
| 1519 | ``K = min(M, N)``. |
| 1520 | compute_uv : bool, optional |
| 1521 | Whether or not to compute `u` and `vh` in addition to `s`. True |
| 1522 | by default. |
| 1523 | hermitian : bool, optional |
| 1524 | If True, `a` is assumed to be Hermitian (symmetric if real-valued), |
| 1525 | enabling a more efficient method for finding singular values. |
| 1526 | Defaults to False. |
| 1527 | |
| 1528 | .. versionadded:: 1.17.0 |
| 1529 | |
| 1530 | Returns |
| 1531 | ------- |
| 1532 | When `compute_uv` is True, the result is a namedtuple with the following |
| 1533 | attribute names: |
| 1534 | |
| 1535 | U : { (..., M, M), (..., M, K) } array |
| 1536 | Unitary array(s). The first ``a.ndim - 2`` dimensions have the same |
| 1537 | size as those of the input `a`. The size of the last two dimensions |
| 1538 | depends on the value of `full_matrices`. Only returned when |
| 1539 | `compute_uv` is True. |
| 1540 | S : (..., K) array |
| 1541 | Vector(s) with the singular values, within each vector sorted in |
| 1542 | descending order. The first ``a.ndim - 2`` dimensions have the same |
| 1543 | size as those of the input `a`. |
| 1544 | Vh : { (..., N, N), (..., K, N) } array |
| 1545 | Unitary array(s). The first ``a.ndim - 2`` dimensions have the same |
| 1546 | size as those of the input `a`. The size of the last two dimensions |
| 1547 | depends on the value of `full_matrices`. Only returned when |
| 1548 | `compute_uv` is True. |
| 1549 | |
| 1550 | Raises |
| 1551 | ------ |
| 1552 | LinAlgError |
| 1553 | If SVD computation does not converge. |
| 1554 | |
| 1555 | See Also |
| 1556 | -------- |
| 1557 | scipy.linalg.svd : Similar function in SciPy. |
no test coverage detected