当前位置:网站首页>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
边栏推荐
- P5076 [deep base 16. Example 7] common binary tree (simplified version)
- 20 shortcut keys for vs code!
- New product release Junda intelligent integrated environmental monitoring terminal
- P5076 【深基16.例7】普通二叉樹(簡化版)
- leetcode:207. 课程表
- typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;
- How to determine the sample size of an inspection lot in SAP QM's initial sampling strategy?
- 部署static pod方式部署etcd集群
- JS中如何实现重载
- leetcode:210. 课程表 II
猜你喜欢

Lightroom 大使系列:用 Meg Loeks 捕捉怀旧之情

typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;

At the same time, do the test. Others have been paid 20W a year. Why are you still working hard to reach 10K a month?

Design rule check constraint (set_max_transition, set_max_capability)

leetcode:210. 課程錶 II

Lombok package is successfully installed, but the runtime prompts that get, set method and constructor solution cannot be found

跳槽前恶补面试题,金三成功上岸腾讯,拿到30k的测开offer

测试人如何规划自己的未来?才能实现入行2年达到25k?

作用域和作用域链

Library cache lock brought by add trandata
随机推荐
Compréhension préliminaire des expressions régulières cognitives (regex)
Successful transition from self-study test halfway, 10K for the first test
JS深浅拷贝
竣达技术丨适用于“科士达”智能精密空调网络监控
Let Google browser fofa plug-in come alive
初步了解认识正则表达式(Regex)
How can CTCM in the inspection lot system status of SAP QM be eliminated?
leetcode:210. 課程錶 II
My way of programming
Fcpx tutorial, how to export video graphics and text in Final Cut Pro?
Maximize tensorflow* CPU performance (shell)
[live streaming] understand the design of d3js and learn how to read the source code.
Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot
Li Mu [practical machine learning] 1.4 data annotation
同花顺能开户吗,在APP上可以直接开通券商安全吗 ,买股票怎么网上开户
最简单ALV模板
Shell language
A Zhu and Xu Baobao's high-rise game - difference
Large and small end conversion
The required books for software testers (with e-books) recommended by senior Ali have benefited me a lot