def diagsvd(s, M, N):
part = diag(s)<EOL>typ = part.dtype.char<EOL>MorN = len(s)<EOL>if MorN == M:<EOL><INDENT>return r_['<STR_LIT>', part, zeros((M, N-M), typ)]<EOL><DEDENT>elif MorN == N:<EOL><INDENT>return r_[part, zeros((M-N,N), typ)]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>
Construct the sigma matrix in SVD from singular values and size M, N.

Parameters
----------
s : (M,) or (N,) array_like
    Singular values
M : int
    Size of the matrix whose singular values are `s`.
N : int
    Size of the matrix whose singular values are `s`.

Returns
-------
S : (M, N) ndarray
    The S-matrix in the singular value decomposition