Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python torch.gather ()

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report