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

边栏推荐
- SQL每日一练(牛客新题库)——第5天:高级查询
- 国内IT市场还有发展吗?有哪些创新好用的IT运维工具可以推荐?
- JMeter接口自动化发包与示例
- ArcEngine (six) use the tool tool to realize the zoom in, zoom out and translation of the pull box
- frp:开源内网穿透工具
- "Swordsman Offer" brush questions print from 1 to the largest n digits
- Guava的缓存
- ArcEngine (3) zoom in and zoom out through the MapControl control to achieve full-image roaming
- 流行和声基础大笔记
- IDEA的database使用教程(使用mysql数据库)
猜你喜欢

How does Mysql query two data tables for the same fields in two tables at the same time

热部署系统实现

Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
redis stream 实现消息队列

审批流设计

二进制日志过期时间设置expire_logs_days

Logic Pro X自带音色库列表

Docker starts mysql

dflow入门2——Slices

【TPC-DS】25张表的详细介绍,SQL的查询特征
随机推荐
ArcEngine (4) Use of MapControl_OnMouseDown
dflow入门3——dpdispatcher插件
002-字段不为null
用diskpart的offline命令弹出顽固硬盘
服务器资源监控工具-nmon、nmon_analyser
dflow入门5——Big step & Big parameter
window的供选数据流
【愚公系列】2022年07月 Go教学课程 026-结构体
netstat 及 ifconfig 是如何工作的。
redis键值出现 xacxedx00x05tx00&的解决方法
0day_Topsec上网行为管理RCE
审批流设计
二进制日志过期时间设置expire_logs_days
C# 一周入门高级编程之《C#-接口》Day Two
阿里云·短信发送
mysql服务器上的mysql这个实例中表的介绍
实时目标检测新高地之#YOLOv7#更快更强的目标检测器
How does Mysql query two data tables for the same fields in two tables at the same time
HCIP练习(OSPF)
HCIA实验(07)