mindspore.scipy.linalg.lu
- mindspore.scipy.linalg.lu(a, permute_l=False, overwrite_a=False, check_finite=True)[source]
Compute pivoted LU decomposition of a general matrix.
The decomposition is:
where
is a permutation matrix, lower triangular with unit diagonal elements, and upper triangular.- Parameters
a (Tensor) – a
matrix to decompose. Note that if the input tensor is not a float, then it will be casted to :class:’mstype.float32’.permute_l (bool, optional) – Perform the multiplication
(Default: do not permute). Default: False.overwrite_a (bool, optional) – Whether to overwrite data in
(may improve performance). Default: False.check_finite (bool, optional) – Whether to check that the input matrix contains only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs. Default: True.
- Returns
If permute_l == False
Tensor,
permutation matrix.Tensor,
lower triangular or trapezoidal matrix with unit diagonal. .Tensor,
upper triangular or trapezoidal matrix.
If permute_l == True
Tensor,
permuted L matrix. .Tensor,
upper triangular or trapezoidal matrix.
- Supported Platforms:
CPU
GPU
Examples
>>> import numpy as onp >>> from mindspore.common import Tensor >>> from mindspore.scipy.linalg import lu >>> A = Tensor(onp.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]]).astype(onp.float64)) >>> p, l, u = lu(A) >>> p Tensor(shape=[4, 4], dtype=Int32, value= [[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0]]) >>> l Tensor(shape=[4, 4], dtype=Float64, value= [[ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 2.85714298e-01, 1.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 7.14285731e-01, 1.19999997e-01, 1.00000000e+00, 0.00000000e+00], [ 7.14285731e-01, -4.39999998e-01, -4.61538464e-01, 1.00000000e+00]]) >>> u Tensor(shape=[4, 4], dtype=Float64, value= [[ 7.00000000e+00, 5.00000000e+00, 6.00000000e+00, 6.00000000e+00], [ 0.00000000e+00, 3.57142854e+00, 6.28571415e+00, 5.28571415e+00], [ 0.00000000e+00, 0.00000000e+00, -1.03999996e+00, 3.07999992e+00], [ 0.00000000e+00, -0.00000000e+00, -0.00000000e+00, 7.46153831e+00]])