# lu¶

paddle.linalg. lu ( x, pivot=True, get_infos=False, name=None ) [source]

Computes the LU factorization of an N-D(N>=2) matrix x.

Returns the LU factorization(inplace x) and Pivots. low triangular matrix L and upper triangular matrix U are combined to a single LU matrix.

Pivoting is done if pivot is set to True. P mat can be get by pivots: # ones = eye(rows) #eye matrix of rank rows # for i in range(cols): # swap(ones[i], ones[pivots[i]]) # return ones

Parameters
• X (Tensor) – the tensor to factor of N-dimensions(N>=2).

• pivot (bool, optional) – controls whether pivoting is done. Default: True.

• get_infos (bool, optional) – if set to True, returns an info IntTensor. Default: False.

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

Returns

LU matrix, the factorization of input X.

pivots (IntTensor): the pivots of size(∗(N-2), min(m,n)). pivots stores all the

intermediate transpositions of rows. The final permutation perm could be reconstructed by this, details refer to upper example.

infos (IntTensor, optional): if get_infos is True, this is a tensor of size (∗(N-2))

where non-zero values indicate whether factorization for the matrix or each minibatch has succeeded or failed.

Return type

factorization (Tensor)

Examples

```import paddle

x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')

# >>> lu:
# Tensor(shape=[3, 2], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
#    [[5.        , 6.        ],
#        [0.20000000, 0.80000000],
#        [0.60000000, 0.50000000]])
# >>> p
#    [3, 3])
# >>> info
#    0)

# >>> P
# (Tensor(shape=[3, 3], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
# [[0., 1., 0.],
# [0., 0., 1.],
# [1., 0., 0.]]),
# >>> L
# Tensor(shape=[3, 2], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
# [[1.        , 0.        ],
# [0.20000000, 1.        ],
# [0.60000000, 0.50000000]]),
# >>> U
# Tensor(shape=[2, 2], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
# [[5.        , 6.        ],
# [0.        , 0.80000000]]))

# one can verify : X = P @ L @ U ;
```