solve

paddle.linalg. solve ( x, y, name=None ) [source]

Computes the solution of a square system of linear equations with a unique solution for input ‘X’ and ‘Y’. Let :math: X be a sqaure matrix or a batch of square matrices, \(Y\) be a vector/matrix or a batch of vectors/matrices, the equation should be:

\[Out = X^-1 * Y\]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/tensor/linalg.py:docstring of paddle.tensor.linalg.solve, line 7)

Explicit markup ends without a blank line; unexpected unindent.

Specifically, - This system of linear equations has one solution if and only if input ‘X’ is invertible.

Parameters
  • x (Tensor) – A square matrix or a batch of square matrices. Its shape should be [*, M, M], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • y (Tensor) – A vector/matrix or a batch of vectors/matrices. Its shape should be [*, M, K], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

The solution of a square system of linear equations with a unique solution for input ‘x’ and ‘y’. Its data type should be the same as that of x.

Return type

Tensor

Examples: .. code-block:: python

# a square system of linear equations: # 2*X0 + X1 = 9 # X0 + 2*X1 = 8

import paddle import numpy as np

np_x = np.array([[3, 1],[1, 2]]) np_y = np.array([9, 8]) x = paddle.to_tensor(np_x, dtype=”float64”) y = paddle.to_tensor(np_y, dtype=”float64”) out = paddle.linalg.solve(x, y)

print(out) # [2., 3.])