cupy.linalg.lstsq#
- cupy.linalg.lstsq(a, b, rcond='warn')[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) – Cutoff parameter for small singular values. For stability it computes the largest singular value denoted by
s, and sets all singular values smaller thansto zero.
- Returns:
A tuple of
(x, residuals, rank, s). Notexis the least-squares solution with shape(N,)or(N, K)depending ifbwas two-dimensional. The sums ofresidualsis the squared Euclidean 2-norm for each column in b - a*x. Theresidualsis 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,). Therankof matrixais an integer. The singular values ofaares.- 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