当前位置:网站首页>torch. unique()
torch. unique()
2022-06-12 20:57:00 【Human high quality Algorithm Engineer】
torch.unique() The function of is similar to the set in mathematics , Is to pick out tensor Independent non repeating elements in .
The parameters of this method are listed in the official interpretation document :torch.unique(input, sorted=True, return_inverse=False, return_counts=False, dim=None)
input: To be dealt with tensor
sorted: Whether to arrange the returned unrepeated tensors in numerical values , By default, it is arranged in sequence
return_inverse: Whether to return to the original tensor The index of each element in this non repeating tensor
return_counts: Count the number of each independent element in the original tensor
dim: Which dimension does the value go along unique To deal with , I didn't understand the mechanism after the experiment . If all the tensors are one-dimensional , Then this need not be ignored .
The following is an experimental explanation and analysis of these different parameters .
import torch
x = torch.tensor([4,0,1,2,1,2,3])# Generate a tensor, As experimental input
print(x)
out = torch.unique(x) # All parameters are set to default
print(out)# Print out the processing results
# give the result as follows :
#tensor([0, 1, 2, 3, 4]) # take x The non repeating elements in are singled out , And the default is sequence arrangement
out = torch.unique(x,sorted=False)# Change the default sort order to False
print(out)
# The output is as follows :
#tensor([3, 2, 1, 0, 4]) # take x Found the independent elements in , Just output in the original order
out = torch.unique(x,return_inverse=True)# Output the index of each element in the original data in the newly generated independent element tensor
print(out)
# The output is as follows :
#(tensor([0, 1, 2, 3, 4]), tensor([4, 0, 1, 2, 1, 2, 3])) # The first tensor is the independent tensor output after sorting , The second result corresponds to the index of each element in the original data in the new independent non repeating tensor , such as x[0]=4, The index in the new tensor is 4, x[1]=0, The index in the new tensor is 0,x[6]=3, The index in the new tensor is 3
out = torch.unique(x,return_counts=True) # Returns the number of each independent element
print(out)
# The output is as follows
#(tensor([0, 1, 2, 3, 4]), tensor([1, 2, 2, 1, 1])) #0 The number of this element in the original data is 1,1 The number of this element in the original data is 2
Reprinted from :https://blog.csdn.net/t20134297/article/details/108235355
边栏推荐
- Deploy etcd cluster in static pod mode
- Market trend report, technical innovation and market forecast of hydraulic torque wrench in China
- Social metauniverse: start from redefining yourself
- 对闭包的理解
- How to improve communication efficiency during home office | community essay solicitation
- 解决cvxpy报错The solver GLPK_MI is not installed
- Summary of machine learning materials
- Go -- monitor file changes
- remote: Support for password authentication was removed on August 13, 2021
- Solution of multi machine room dynamic loop status network touch screen monitoring
猜你喜欢
随机推荐
typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;
Why my order by create_ Time ASC becomes order by ASC
解决cvxpy报错The solver GLPK_MI is not installed
Li Mu [practical machine learning] 1.4 data annotation
Understanding of closures
对闭包的理解
(11) Image frequency domain filtering with OpenCV
Go -- monitor file changes
居家办公期间如何提升沟通效率|社区征文
QT pro file configuration ffmpeg macro
Data visualization - biaxial comparison effect
Circularly insert one excel column and the sum of multiple columns
循环插入excel某一列,以及多列之和
Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app? How to open an account online when buying stocks
Maximize tensorflow* CPU performance (shell)
JS deep and shallow copy
It has been engaged in the functional test of 10K to the test development of 40W annual salary for 5 years, and spent 7 days sorting out the super comprehensive learning route
P5076 [deep base 16. Example 7] common binary tree (simplified version)
How to download putty using alicloud image?
new做了哪几件事









