YouTip LogoYouTip

Pytorch Torch Linalg Matrix_Rank

# PyTorch torch.linalg.matrix_rank Function * * * [![Image 3: Pytorch torch Reference Manual]( Pytorch torch Reference Manual]( `torch.linalg.matrix_rank` is a function in the PyTorch linear algebra module used to compute the rank of a matrix. The rank of a matrix represents the number of linearly independent rows or columns in the matrix. ### Function Definition torch.linalg.matrix_rank(A, tol=None, hermitian=False, out=None) **Parameters**: * `A` (Tensor): Input matrix. * `tol` (float, optional): Singular value threshold. * `hermitian` (bool, optional): If True, the matrix is assumed to be Hermitian (symmetric). Default is False. * `out` (Tensor, optional): Output tensor. **Returns**: * `torch.Tensor`: Returns the rank of the matrix. * * * ## Usage Examples ## Example import torch # Create full-rank matrix A = torch.tensor([[1.0,2.0,3.0], [4.0,5.0,6.0], [7.0,8.0,9.0]]) # Compute matrix rank rank = torch.linalg.matrix_rank(A) print("Matrix A:") print(A) print("Matrix rank:", rank) Output: Matrix A: tensor([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])Matrix rank: tensor(2) ## Example - Full-Rank Matrix import torch # Create full-rank matrix B = torch.tensor([[1.0,2.0], [3.0,4.0]]) rank_B = torch.linalg.matrix_rank(B) print("Matrix B:") print(B) print("Matrix rank:", rank_B) * * * [![Image 4: Pytorch torch Reference Manual]( Pytorch torch Reference Manual](
← Pytorch Torch Linalg PinvPytorch Torch Linalg Matmul β†’