当前位置:网站首页>pytorch one-hot tips
pytorch one-hot tips
2022-08-03 08:32:00 【OPTree412】
首先介绍一下np.eye()
numpy.eye(N,M=None,k=0,dtype=<class 'float'>,order='C)
| 参数 | 类型 | Value |
|---|---|---|
| N | int | Indicates the number of lines of output |
| M | int型 | 输出的列数,默认为N |
| k | int型 | 对角线的下标,默认为0表示的是主对角线,负数表示的是低对角,正数表示的是高对角. |
| dtype | $1 | 数据的类型,可选项,The data type of the returned data |
| order | {‘C’,‘F’} | 可选项,That is, the form of the output array is in accordance withClanguage line precedence’C’,还是按照FortranColumn-majority of the form‘F’存储在内存中 |
例子:
import numpy as np
labels = np.array([[1], [2], [0], [1]])
print("labels的大小:", labels.shape, "\n")
# Because our category is from0-2,所以这里是3个类
a = np.eye(3)[1]
print("If the corresponding category number is 1,那么转成one-hot的形式", a, "\n")
a = np.eye(3)[2]
print("If the corresponding category number is 2,那么转成one-hot的形式", a, "\n")
a = np.eye(3)[1, 0]
print("1转成one-hotThe first number of the array is :", a, "\n")
# The difference between the results here and above,注意!!!
a = np.eye(3)[[1, 2, 0, 1]]
print("If the corresponding category number is 1,2,0,1,那么转成one-hot的形式\n", a)
res = np.eye(3)[labels.reshape(-1)]
print("labels转成one-hot形式的结果:\n", res, "\n")
print("labels转化成one-hot后的大小:", res.shape)

边栏推荐
猜你喜欢
随机推荐
AcWing 3391. 今年的第几天?(简单题)
进程信息
dflow入门1——HelloWorld!
2022下半年软考「高项&集成」复习计划ta来喽~
Guava的Service
sqlite date field plus one day
ArcEngine(四)MapControl_OnMouseDown的使用
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
MySQL2
netstat 及 ifconfig 是如何工作的。
并发之固定运行和交替运行方案
HCIP实验(06)
实时目标检测新高地之#YOLOv7#更快更强的目标检测器
内存模型之可见性
并发之ReentrantLock
判断根节点是否等于子节点之和
Eject stubborn hard drives with diskpart's offline command
关于Unity,Laya学习,第一步加载Unity加载场景









