#### Previous topic

scipy.linalg.norm

#### Next topic

scipy.linalg.pinv

# scipy.linalg.lstsq

`scipy.linalg.``lstsq`(a, b, cond=None, overwrite_a=False, overwrite_b=False, check_finite=True)

  Compute least-squares solution to equation Ax = b.

  Compute a vector x such that the 2-norm `|b - A x|` is minimized.

  Parameters: | a : (M, N) array_like Left hand side matrix (2-D array). b : (M,) or (M, K) array_like Right hand side matrix or vector (1-D or 2-D array). cond : float, optional Cutoff for ‘small’ singular values; used to determine effective rank of a. Singular values smaller than `rcond * largest_singular_value` are considered zero. overwrite_a : bool, optional Discard data in a (may enhance performance). Default is False. overwrite_b : bool, optional Discard data in b (may enhance performance). Default is False. check_finite : bool, optional Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
  Returns: | x : (N,) or (N, K) ndarray Least-squares solution. Return shape matches shape of b. residues : () or (1,) or (K,) ndarray Sums of residues, squared 2-norm for each column in `b - a x`. If rank of matrix a is < N or > M this is an empty array. If b was 1-D, this is an (1,) shape array, otherwise the shape is (K,). rank : int Effective rank of matrix a. s : (min(M,N),) ndarray Singular values of a. The condition number of a is `abs(s[0]/s[-1])`.
  Raises: | LinAlgError : If computation does not converge.

  See also

  `optimize.nnls`
    linear least squares with non-negativity constraint