cupy.linalg.lstsq#
- cupy.linalg.lstsq(a, b, rcond=None)[source]#
Return the least-squares solution to a linear matrix equation.
Solves the equation a x = b by computing a vector x that minimizes the Euclidean 2-norm || b - a x ||^2. The equation may be under-, well-, or over- determined (i.e., the number of linearly independent rows of a can be less than, equal to, or greater than its number of linearly independent columns). If a is square and of full rank, then x (but for round-off error) is the “exact” solution of the equation.
- Parameters:
a (cupy.ndarray) – “Coefficient” matrix with dimension
(M, N)
b (cupy.ndarray) – “Dependent variable” values with dimension
(M,)
or(M, K)
rcond (float, optional) – Cutoff parameter for small singular values. For stability it computes the largest singular value denoted by
s
, and sets all singular values smaller thans
to zero.
- Returns:
A tuple of
(x, residuals, rank, s)
. Notex
is the least-squares solution with shape(N,)
or(N, K)
depending ifb
was two-dimensional. The sums ofresiduals
is the squared Euclidean 2-norm for each column in b - a*x. Theresiduals
is an empty array if the rank of a is < N or M <= N, but iff b is 1-dimensional, this is a (1,) shape array, Otherwise the shape is (K,). Therank
of matrixa
is an integer. The singular values ofa
ares
.- Return type:
Warning
This function calls one or more cuSOLVER routine(s) which may yield invalid results if input conditions are not met. To detect these invalid results, you can set the linalg configuration to a value that is not ignore in
cupyx.errstate()
orcupyx.seterr()
.See also