当前位置:网站首页>torch.nn.functional.one_hot()
torch.nn.functional.one_hot()
2022-07-29 08:04:00 【00000cj】
参数
- tensor(LongTensor),任意shape的类别值
- num_classes(int),所有类别的数量。默认为-1,如果设为-1,num_classes=tensor中最大的值+1
定义
假设tensor的shape为( * ),函数返回shape为( *, num_classes)的tensor,返回的tensor中除了最后一维索引为tensor对应值位置为1,其它都为0。
示例
target1 = torch.tensor([1, 2, 3])
print(target1.shape) # torch.Size([3])
print(target1) # tensor([1, 2, 3])
target1 = torch.nn.functional.one_hot(target1, num_classes=5)
print(target1.shape) # torch.Size([3, 5])
print(target1)
# tensor([[0, 1, 0, 0, 0],
# [0, 0, 1, 0, 0],
# [0, 0, 0, 1, 0]])
target2 = torch.tensor([1, 2, 3])
target2 = torch.nn.functional.one_hot(target2)
print(target2.shape) # torch.Size([3, 4])
print(target2)
# tensor([[0, 1, 0, 0],
# [0, 0, 1, 0],
# [0, 0, 0, 1]])参考
边栏推荐
- postman接口测试|js脚本之阻塞休眠和非阻塞休眠
- 关于pip升级损坏导致的问题记录
- STM32 detection signal frequency
- Actual measurement of boot and pH pins of buck circuit
- How to draw an excellent architecture diagram
- Ansible (automation software)
- Compare three clock circuit schemes of single chip microcomputer
- Keyboard processing in jetpack compose
- [beauty of software engineering - column notes] 24 | technical debt: continue to make do with it, or overthrow it and start over?
- Joseph Ring problem
猜你喜欢
![[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging](/img/50/594dfc9affbcca97166d475fe09ad3.png)
[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging
![[beauty of software engineering - column notes] 22 | how to do a good job in technology selection for the project?](/img/1a/72bfb3fef59c54188a823ead3a5390.png)
[beauty of software engineering - column notes] 22 | how to do a good job in technology selection for the project?

Amaze UI icon query
![[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M](/img/5e/69987afcd1e50ba37bc49441dd3a50.png)
[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M

Compare three clock circuit schemes of single chip microcomputer

Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
![[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging](/img/1e/9f05862288261e16a6b04508b9b292.png)
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging

UE4 highlight official reference value

The smallest positive number that a subset of an array cannot accumulate

Data unit: bit, byte, word, word length
随机推荐
[skill accumulation] presentation practical skill accumulation, common sentence patterns
Matrix decomposition and gradient descent
[paper reading] tomoalign: a novel approach to correcting sample motion and 3D CTF in cryoet
Character shader exercise
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
[untitled] format save
[cryoEM] Introduction to FSC, Fourier shell correlation
Record of problems caused by PIP upgrade damage
Some tools, plug-ins and software links are shared with you~
Technology sharing | quick intercom integrated dispatching system
[cryoelectron microscope] relion4.0 pipeline command summary (self use)
C# 之 volatile关键字解析
10 common software architecture modes
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging
[密码学实验] 0x00 安装NTL库
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
What is the use of chat robots? What type? After reading these, you will understand!
How to get to the deep-water area when the industrial Internet goes?
What are the principles and methods of implementing functional automation testing?
Beautiful girls