本文簡要介紹python語言中 torch.linalg.matrix_norm 的用法。
用法:
torch.linalg.matrix_norm(A, ord='fro', dim=(- 2, - 1), keepdim=False, *, dtype=None, out=None) → Tensorout(Tensor,可選的) -輸出張量。如果
None則忽略。默認值:None。dtype(
torch.dtype, 可選的) -如果指定,則在執行操作之前輸入張量將轉換為dtype,並且返回的張量的類型將為dtype。默認值:None
一個實值張量,即使
A是複數。計算矩陣範數。
如果
A是複數值,則計算A.abs()的範數支持 float、double、cfloat 和 cdouble 數據類型的輸入。還支持批量矩陣:範數將在 2 元組
dim指定的維度上計算,其他維度將被視為批量維度。輸出將具有相同的批次尺寸。ord定義計算的矩陣範數。支持以下規範:ord矩陣範數
‘fro’(默認)弗羅貝尼烏斯範數
‘nuc’核規範
infmax(sum(abs(x), dim=1))-infmin(sum(abs(x), dim=1))1max(sum(abs(x), dim=0))-1min(sum(abs(x), dim=0))2最大奇異值
-2最小奇異值
其中
inf指的是float(‘inf’)、NumPy 的inf對象或任何等效對象。例子:
>>> from torch import linalg as LA >>> A = torch.arange(9, dtype=torch.float).reshape(3, 3) >>> A tensor([[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]]) >>> LA.matrix_norm(A) tensor(14.2829) >>> LA.matrix_norm(A, ord=-1) tensor(9.) >>> B = A.expand(2, -1, -1) >>> B tensor([[[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]], [[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]]]) >>> LA.matrix_norm(B) tensor([14.2829, 14.2829]) >>> LA.matrix_norm(B, dim=(0, 2)) tensor([ 3.1623, 10.0000, 17.2627])
參數:
關鍵字參數:
返回:
相關用法
- Python PyTorch matrix_rank用法及代碼示例
- Python PyTorch matrix_exp用法及代碼示例
- Python PyTorch matrix_power用法及代碼示例
- Python PyTorch matmul用法及代碼示例
- Python PyTorch max用法及代碼示例
- Python PyTorch maximum用法及代碼示例
- Python PyTorch masked_select用法及代碼示例
- Python PyTorch maskrcnn_resnet50_fpn用法及代碼示例
- Python PyTorch make_tensor用法及代碼示例
- Python PyTorch monitored_barrier用法及代碼示例
- Python PyTorch mean用法及代碼示例
- Python PyTorch multinomial用法及代碼示例
- Python PyTorch meshgrid用法及代碼示例
- Python PyTorch mm用法及代碼示例
- Python PyTorch mv用法及代碼示例
- Python PyTorch min用法及代碼示例
- Python PyTorch msort用法及代碼示例
- Python PyTorch mode用法及代碼示例
- Python PyTorch movedim用法及代碼示例
- Python PyTorch minimum用法及代碼示例
- Python PyTorch multi_dot用法及代碼示例
- Python PyTorch mul用法及代碼示例
- Python PyTorch movielens_25m用法及代碼示例
- Python PyTorch multigammaln用法及代碼示例
- Python PyTorch movielens_20m用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.linalg.matrix_norm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
