代码拉取完成,页面将自动刷新
torch.nn.functional.normalize(
input,
p=2,
dim=1,
eps=1e-12,
out=None
)
For more information, see torch.nn.functional.normalize.
class mindspore.ops.L2Normalize(
axis=0,
epsilon=1e-4
)(input_x)
For more information, see mindspore.ops.L2Normalize.
PyTorch: Supports using the LP paradigm by specifying the parameter p
.
MindSpore:Only L2 paradigm is supported.
import mindspore as ms
import mindspore.ops as ops
import torch
import numpy as np
# In MindSpore, you can directly pass data into the function, and the default dimension is 0.
l2_normalize = ops.L2Normalize()
input_x = ms.Tensor(np.array([1.0, 2.0, 3.0]), ms.float32)
output = l2_normalize(input_x)
print(output)
# Out:
# [0.2673 0.5345 0.8018]
# In torch, parameter p should be set to determine it is a lp normalization, and the default dimension is 1.
input_x = torch.tensor(np.array([1.0, 2.0, 3.0]))
outputL2 = torch.nn.functional.normalize(input=input_x, p=2, dim=0)
outputL3 = torch.nn.functional.normalize(input=input_x, p=3, dim=0)
print(outputL2)
print(outputL3)
# Out:
# tensor([0.2673, 0.5345, 0.8018], dtype=torch.float64)
# tensor([0.3029, 0.6057, 0.9086], dtype=torch.float64)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。