import torch import torchvision import torch.nn as nn import torch.nn.functional as F x = torch.randn(3, 4) print(x) print() sorted, indices = torch.sort(x) print(sorted) print(indices) sorted, indices = torch.sort(x, 0) print(sorted) print(indices)
D:ProgramDataMiniconda3python.exe E:/新脚本主文件夹/训练测试项目/test_torch/sort.py tensor([[ 1.0198, 0.6535, -0.5993, -1.2033], [-1.2741, -0.1615, -1.4329, -2.1151], [-1.8084, -0.3558, 0.6515, -0.2942]]) tensor([[-1.2033, -0.5993, 0.6535, 1.0198], [-2.1151, -1.4329, -1.2741, -0.1615], [-1.8084, -0.3558, -0.2942, 0.6515]]) tensor([[3, 2, 1, 0], [3, 2, 0, 1], [0, 1, 3, 2]]) tensor([[-1.8084, -0.3558, -1.4329, -2.1151], [-1.2741, -0.1615, -0.5993, -1.2033], [ 1.0198, 0.6535, 0.6515, -0.2942]]) tensor([[2, 2, 1, 1], [1, 1, 0, 0], [0, 0, 2, 2]]) Process finished with exit code 0