How to use torch.sort () of Python
This article mainly introduces "how to use torch.sort () of Python". In daily operation, I believe many people have doubts about how to use torch.sort () of Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use torch.sort () of Python"! Next, please follow the editor to study!
The code experiment shows:
Microsoft Windows [version 10.0.18363.1256] (c) 2019 Microsoft Corporation. All rights reserved. C:\ Users\ chenxuqi > conda activate ssd4pytorch2_2_0 (ssd4pytorch2_2_0) C:\ Users\ chenxuqi > pythonPython 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]:: Anaconda, Inc. On win32Type "help", "copyright", "credits" or "license" for more information. > import torch > > torch.manual_seed (seed=20200910) > x = torch.randn (3, 4) > > xtensor ([[0.2824,-0.3715, 0.9088) -1.7601], [- 0.1806, 2.0937, 1.0406,-1.7651], [1.1216, 0.8440, 0.1783, 0.6859]) > sorted, indices = torch.sort (x) > sortedtensor ([[- 1.7601,-0.3715,0.2824,0.9088], [- 1.7651,-0.1806,1.0406,2.0937], [0.1783,0.6859,0.8440) 1.1216]) > indicestensor ([[3,1,0,2], [3,0,2,1], [2,3,1,0]) > sorted, indices = torch.sort (x, 0) > sortedtensor ([[- 0.1806,-0.3715, 0.1783,-1.7651], [0.2824, 0.8440, 0.9088,-1.7601], [1.1216, 2.0937,1.0406] 0.6859]) > indicestensor ([[1,0,2,1], [0,2,0,0], [2,1,1,2]) > xtensor ([[0.2824,-0.3715, 0.9088,-1.7601], [- 0.1806, 2.0937, 1.0406,-1.7651], [1.1216, 0.8440,0.1783,0.6859]) > so far The study on "how to use Python's torch.sort ()" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!