torch.view_as_real#
- torch.view_as_real(input) Tensor#
將
input視為實數張量並返回其檢視。對於一個大小為 的輸入複數張量,此函式返回一個大小為 的新實數張量,其中最後一個大小為 2 的維度代表複數的實部和虛部。警告
view_as_real()僅支援complex dtypes的張量。- 引數
input (Tensor) – 輸入張量。
示例
>>> x=torch.randn(4, dtype=torch.cfloat) >>> x tensor([(0.4737-0.3839j), (-0.2098-0.6699j), (0.3470-0.9451j), (-0.5174-1.3136j)]) >>> torch.view_as_real(x) tensor([[ 0.4737, -0.3839], [-0.2098, -0.6699], [ 0.3470, -0.9451], [-0.5174, -1.3136]])