当前位置:网站首页>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)

边栏推荐
- ArcEngine (3) zoom in and zoom out through the MapControl control to achieve full-image roaming
- HCIP实验(06)
- Evaluate:huggingface评价指标模块入门详细介绍
- RViz报错: Error subscribing: Unable to load plugin for transport ‘compressed‘解决方法
- ArcEngine(一)加载矢量数据
- Docker启动mysql
- 《剑指Offer》刷题之打印从1到最大的n位数
- ArcEngine(二)加载地图文档
- Path Prefixes (倍增!树上の二分)
- ArcEngine(六)用tool工具实现拉框放大缩小和平移
猜你喜欢
随机推荐
《剑指Offer》刷题之打印从1到最大的n位数
DeFi明斯基时刻:压力测试与启示
HCIP练习(OSPF)
【愚公系列】2022年07月 Go教学课程 026-结构体
数据监控平台
ArcEngine (4) Use of MapControl_OnMouseDown
WordPress主题-B2美化通用子主题商业运营版
0day_Topsec上网行为管理RCE
Guava的缓存
长短期记忆网络 LSTM
手把手教你如何自制目标检测框架(从理论到实现)
wordpress: 裁剪您的图片时发生错误
AI中台序列标注任务:三个数据集构造过程记录
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
Eject stubborn hard drives with diskpart's offline command
并发之多把锁和活跃性
Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
进程信息
ArcEngine (1) Loading vector data
Nacos使用实践









