代码拉取完成,页面将自动刷新
torch.Tensor.float(memory_format=torch.preserve_format)
For more information, see torch.Tensor.float.
class mindspore.ops.Cast(*args, **kwargs)(
input_x,
type
)
For more information, see mindspore.ops.Cast.
PyTorch: Changes the tensor type to float.
MindSpore:Converts the input type to the specified data type.
import mindspore as ms
import mindspore.ops as ops
import torch
import numpy as np
# In MindSpore, you can specify the data type to be transformed into.
input_x = ms.Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32))
cast = ops.Cast()
output = cast(input_x, ms.int32)
print(output.dtype)
print(output.shape)
# Out:
# Int32
# (2, 3, 4, 5)
# In torch, the input will be transformed into float.
input_x = torch.Tensor(np.random.randn(2, 3, 4, 5).astype(np.int32))
output = input_x.float()
print(output.dtype)
print(output.shape)
# Out:
# torch.float32
# torch.Size([2, 3, 4, 5])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。