Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Python torch.gather ()

Shulou Source: shulou.com Published: 2022-06-01 07:55:36 10月04日 Update

This article mainly introduces "how to use Python torch.gather ()". In daily operation, I believe many people have doubts about how to use Python torch.gather (). The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use Python torch.gather ()"! Next, please follow the editor to study!

Instructions for use:

The shapes of input and index parameters must satisfy certain conditions, that is, except on the axis specified by the dim parameter, all other axis shapes must be exactly the same. The shape of the calculated output out is the same as that of index, and the value of out output is given by input. The specific position in input is determined by the position of the current out output and index, the position of dim axis is given by index, and the position of other axes is determined by the current output position of out.

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) > t = torch.tensor ([1MJ 2], [3jue 4]) > > ttensor ([[1J 2]), [3] ) > torch.gather (t, 1, torch.tensor ([[0rect 0], [1J 0]])) tensor ([[1,1], [4,3]]) > index = torch.tensor ([0J 0], [1J 0]]) > indextensor ([[0J 0], [1J 0]]) > torch.gather (t, 1, index) tensor ([1,1], [4,3]]) > torch.gather (t, 0, index) tensor ([[1,2], [3]) 2]]) > so far The study on "how to use Python torch.gather ()" 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!

Tags: Location results learning output shape same parameters more help practical next two code instructions articles methods rights conditions versions theory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Xiaomi Linux NVidia