cupy.linalg.lstsq¶

cupy.linalg.
lstsq
(a, b, rcond=1e15)[source]¶ Return the leastsquares solution to a linear matrix equation.
Solves the equation a x = b by computing a vector x that minimizes the Euclidean 2norm  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 roundoff 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) – 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 leastsquares solution with shape(N,)
or(N, K)
depending ifb
was twodimensional. The sums ofresiduals
is the squared Euclidean 2norm 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 1dimensional, 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
 a (cupy.ndarray) – “Coefficient” matrix with dimension