tf.keras.ops.lstsq

Return the least-squares solution to a linear matrix equation.

Computes the vector x that approximately solves the equation a @ x = b. 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. Else, x minimizes the L2 norm of b - a * x.

If there are multiple minimizing solutions, the one with the smallest L2 norm is returned.

a "Coefficient" matrix of shape (M, N).
b Ordinate or "dependent variable" values, of shape (M,) or (M, K). If b is two-dimensional, the least-squares solution is calculated for each of the K columns of b.
rcond Cut-off ratio for small singular values of a. For the purposes of rank determination, singular values are treated as zero if they are smaller than rcond times the largest singular value of a.

Tensor with shape (N,) or (N, K) containing the least-squares solutions.