代码拉取完成,页面将自动刷新
class torch.argsort(
input,
dim=-1,
descending=False
)
For more information, see torch.argsort.
class mindspore.ops.Sort(
axis=-1,
descending=False
)(x)
For more information, see mindspore.ops.Sort.
PyTorch: Returns the indices that sort a tensor along a given dimension in ascending order by value.
MindSpore: Sorts the elements of the input tensor along a given dimension in ascending order by value. Returns a tensor whose values are the sorted values, and the indices of the elements in the original input tensor.
import numpy as np
import torch
from mindspore import ops
import mindspore as ms
# MindSpore
x = ms.Tensor(np.array([[8, 2, 1], [5, 9, 3], [4, 6, 7]]), ms.float16)
sort = ops.Sort()
output = sort(x)
print(output)
# Out:
# (Tensor(shape=[3, 3], dtype=Float16, value=
# [[ 1.0000e+00, 2.0000e+00, 8.0000e+00],
# [ 3.0000e+00, 5.0000e+00, 9.0000e+00],
# [ 4.0000e+00, 6.0000e+00, 7.0000e+00]]), Tensor(shape=[3, 3], dtype=Int32, value=
# [[2, 1, 0],
# [2, 0, 1],
# [0, 1, 2]]))
# Pytorch
a = torch.tensor([[8, 2, 1], [5, 9, 3], [4, 6, 7]], dtype=torch.int8)
torch.argsort(a, dim=1)
# Out:
# tensor([[2, 1, 0],
# [2, 0, 1],
# [0, 1, 2]])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。