torch.Tensor.float

torch.Tensor.float

torch.Tensor.float(memory_format)

paddle.Tensor.astype

paddle.Tensor.astype(dtype)

两者功能一致,参数名和参数不同,具体如下:

参数差异

| PyTorch | PaddlePaddle | 备注 | | ————- | ———— | —————————————————— | | memory_format | - | tensor 存储形式,转写无需考虑该参数 | |- | dtype | 转换后的 tensor 类型 |

转写示例

# torch 写法
x.float()

# paddle 写法
x.astype('float32')