In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use torch.cat in PyTorch. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Brief introduction of 1.toych
The package torch contains multidimensional data structures and a variety of mathematical operations based on it.
Torch contains the data structure of multi-dimensional tensor and a variety of mathematical operations based on it. In addition, it provides a variety of utilities, some of which can serialize tensors and any type more effectively.
It has a corresponding implementation of CUDA and can perform tensor operations on NVIDIA GPU (computing power > = 3.0).
two。 Tensor Tensors
Torch.is_tensor (obj): returns True if obj is a pytorch tensor
Torch.is_storage (obj): returns True if obj is a pytorch storage object
Torch.numel (input): returns the number of elements in the input tensor.
3.torch.cata = torch.ones ([1jue 2]) b = torch.ones ([1jue 2]) z = torch.cat ([a dint b], 1) aOut [47]: tensor ([[1.1,1.1.1.1.]]) AOut [48]: tensor ([[1, 1]])
If the second parameter is 1 torch.Size torch.cat, you will put ameme b together in columns with the size of 1 (1) 4). If the second parameter is 0, press the line
The rows are put together and the size is torch.Size ([2,2]).
Literally: torch.cat is to splice two tensors (tensor) together, and cat is the meaning of concatenate, that is, splicing, linked together.
Example understanding:
Import torchA = torch.ones (2, 2) A#tensor ([[1, 1, 1.], # [1, 1, 1.]) B=2*torch.ones (4 ~ #) B#tensor ([[2, 2, 2.], # [2, 2, 2.], # [2, 2, 2.], # [2, 2, 2.]) C = torch.cat ((AMague B) 0) # concatenate C#tensor ([[1, 1, 1.], # [1, 1, 1.], # [2, 2, 2.], # [2, 2, 2.], # [2, 2, 2.], # [2, 2, 2.]) D = 2*torch.ones (2, 2, 2.]) M = torch.cat (A) D), 1) # concatenate M#tensor by dimension 1 (column) ([[1, 1, 1, 2, 2, 2.], # [1, 1, 1, 2, 2.]) M.size () # torch.Size ([2, 7])
When using torch.cat ((A _ Magi B), dim), the values of other dimensions need to be the same except that the values of the splicing dimension dim can be different before they can be aligned.
The above is all the contents of the article "how to use torch.cat in PyTorch". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.