MCPcopy Create free account
hub / github.com/dask/dask / svd

Function svd

dask/array/linalg.py:876–966  ·  view source on GitHub ↗

Compute the singular value decomposition of a matrix. Parameters ---------- a : (M, N) Array coerce_signs : bool Whether or not to apply sign coercion to singular vectors in order to maintain deterministic results, by default True. Examples --------

(a, coerce_signs=True)

Source from the content-addressed store, hash-verified

874
875
876def svd(a, coerce_signs=True):
877 """
878 Compute the singular value decomposition of a matrix.
879
880 Parameters
881 ----------
882 a : (M, N) Array
883 coerce_signs : bool
884 Whether or not to apply sign coercion to singular vectors in
885 order to maintain deterministic results, by default True.
886
887 Examples
888 --------
889
890 >>> u, s, v = da.linalg.svd(x) # doctest: +SKIP
891
892 Returns
893 -------
894
895 u : (M, K) Array, unitary / orthogonal
896 Left-singular vectors of `a` (in columns) with shape (M, K)
897 where K = min(M, N).
898 s : (K,) Array, singular values in decreasing order (largest first)
899 Singular values of `a`.
900 v : (K, N) Array, unitary / orthogonal
901 Right-singular vectors of `a` (in rows) with shape (K, N)
902 where K = min(M, N).
903
904 Warnings
905 --------
906
907 SVD is only supported for arrays with chunking in one dimension.
908 This requires that all inputs either contain a single column
909 of chunks (tall-and-skinny) or a single row of chunks (short-and-fat).
910 For arrays with chunking in both dimensions, see da.linalg.svd_compressed.
911
912 See Also
913 --------
914
915 np.linalg.svd : Equivalent NumPy Operation
916 da.linalg.svd_compressed : Randomized SVD for fully chunked arrays
917 dask.array.linalg.tsqr : QR factorization for tall-and-skinny arrays
918 dask.array.utils.svd_flip : Sign normalization for singular vectors
919 """
920 nb = a.numblocks
921 if a.ndim != 2:
922 raise ValueError(
923 "Array must be 2D.\n"
924 "Input shape: {}\n"
925 "Input ndim: {}\n".format(a.shape, a.ndim)
926 )
927 if nb[0] > 1 and nb[1] > 1:
928 raise NotImplementedError(
929 "Array must be chunked in one dimension only. "
930 "This function (svd) only supports tall-and-skinny or short-and-fat "
931 "matrices (see da.linalg.svd_compressed for SVD on fully chunked arrays).\n"
932 "Input shape: {}\n"
933 "Input numblocks: {}\n".format(a.shape, nb)

Callers 3

normFunction · 0.85

Calls 5

delayedFunction · 0.90
from_delayedFunction · 0.90
svd_flipFunction · 0.90
minFunction · 0.85
tsqrFunction · 0.85

Tested by 2