In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Pytorch tensor data type example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Differences in data types between 1.python and pytorch
Strings cannot be displayed in PyTorch, so expressing strings needs to be converted to an encoded type, such as one_hot,word2vec, and so on.
two。 Tensor
In python, there will be a distinction between scalars, vectors, matrices, etc. But in PyTorch, these are collectively called tensor tensor, but the dimensions are different.
A scalar is a 0-dimensional tensor with only one number and no dimension.
A vector is an one-dimensional tensor, which is a sequential number, but there is no distinction between "rows" and "columns".
A matrix is a two-dimensional tensor with shapes, rows and columns.
By analogy, 3-D and 4-D tensors are also commonly used in PyTorch.
The specific ways to generate tensors and obtain related features are as follows:
① one-dimensional tensor
In PyTorch, there are no brackets, only one number, which is the one-dimensional tensor, which is the scalar in python.
You can view the dimensions of the data in different ways:
For the 0-dimensional tensor, when you look at the shape, it is 0.
② two-dimensional tensor
Through Pytorch, you can specify a specific tensor data directly, or you can randomly generate the data of the specified shape by specifying the shape of the tensor.
If the data is generated through numpy, it can be converted into a tensor through torch.from_numpy.
③ 3D tensor
In general, 3D tensors are used in RNN.
④ 4-dimensional tensor
In general, 3D tensors are used in CNN. For example, the four-dimensional tensor generated in the following picture can be understood as two pictures, three layers of color, and the length and width are both 28.
Above, you can generate the tensor of the desired dimension and view the relevant attributes in different ways.
After reading the above, have you mastered the method of example analysis of Pytorch tensor data types? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.