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]])