当前位置:网站首页>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
边栏推荐
- Compréhension préliminaire des expressions régulières cognitives (regex)
- 可测性设计学习笔记
- Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer
- 最简单ALV模板
- How to improve communication efficiency during home office | community essay solicitation
- Composer version degradation
- New product release Junda intelligent integrated environmental monitoring terminal
- Simplest ALV template
- How do testers plan for their future? To achieve 25K in 2 years?
- Restful API 接口规范
猜你喜欢
Junda technology is applicable to "kestar" intelligent precision air conditioning network monitoring
JSP中的监听器
Data visualization - histogram
Algorinote_2_主定理与 Akra-Bazzi 定理
入行5年从10k的功能测试到年薪40w的测试开发,花7天时间整理的超全学习路线
Illustrator tutorial, how to recolor artwork in illustrator?
新品发布丨竣达智能综合环境监测终端
2022年春招,测试工程师全套面试攻略,一篇吃透全部技术栈(全是干货)
What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8
阿里前辈给我推荐的软件测试人员必读书籍(附电子书),让我受益匪浅...
随机推荐
Minio client (MC command) implements data migration
Data visualization - biaxial comparison effect
Properties to YML
Inrelease: the following signature cannot be verified because there is no public key: no_ PUBKEY EB3E94ADBE1229CF
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
Data visualization - Calendar chart
[leetcode 16 solution] the sum of the nearest three numbers
Design rule check constraint (set_max_transition, set_max_capability)
JS深浅拷贝
多机房动环状态网络触摸屏监控解决方案
Data visualization - histogram
Do we media video, and share the necessary app for friendly new media operation
函数的了解
Introduction to system mode development of rouya wechat mall
设计规则检查约束(set_max_transition、set_max_capacitance)
JS中如何实现重载
Composer version degradation
new做了哪几件事
shell语言
remote: Support for password authentication was removed on August 13, 2021