代码拉取完成,页面将自动刷新
torch.unique(
input,
sorted=True,
return_inverse=False,
return_counts=False,
dim=None
)
For more information, see torch.unique.
class mindspore.ops.Unique(*args, **kwargs)(x)
For more information, see mindspore.ops.Unique.
PyTorch: By setting relevant parameters, determines whether to sort the output, to return indices of elements in the input corresponding to the output tensor, to return counts for each unique element.
MindSpore: Outputs all unique elements in ascending order, and returns indices of elements in the input corresponding to the output tensor.
import mindspore as ms
import mindspore.ops as ops
import torch
import numpy as np
# In MindSpore, the tensor containing unique elements in ascending order.
# As well as another tensor containing the corresponding indices will be directly returned.
x = ms.Tensor(np.array([1, 2, 5, 2]), ms.int32)
unique = ops.Unique()
output, indices = unique(x)
print(output)
print(indices)
# Out:
# [1 2 5]
# [0 1 2 1]
# In torch, parameters can be set to determine whether to output tensor containing unique elements in ascending order.
# As well as whether to output tensor containing corresponding indices.
x = torch.tensor([1, 2, 5, 2])
output, indices = torch.unique(x, sorted=True, return_inverse=True)
print(output)
print(indices)
# Out:
# tensor([1, 2, 5])
# tensor([0, 1, 2, 1])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。