当前位置:网站首页>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)
边栏推荐
猜你喜欢
Logic Pro X built-in sound library list
How does Mysql query two data tables for the same fields in two tables at the same time
pytorch one-hot 小技巧
JMeter接口自动化发包与示例
"Swordsman Offer" brush questions print from 1 to the largest n digits
线性表
BOM系列之localStorage
热部署系统实现
二进制日志过期时间设置expire_logs_days
MySQL数据库————数据库与vs的连接
随机推荐
2022下半年软考「高项&集成」复习计划ta来喽~
行业 SaaS 微服务稳定性保障实战
Gauva的ListenableFuture
dflow入门5——Big step & Big parameter
sqlite 日期字段加一天
uniapp swiper 卡片轮播 修改指示点样式效果demo(整理)
Redis的基础与django使用redis
内存模型之可见性
[Kaggle combat] Prediction of the number of survivors of the Titanic (from zero to submission to Kaggle to model saving and restoration)
ArcEngine (1) Loading vector data
Laya中关于摄像机跟随人物移动或者点击人物碰撞器触发事件的Demo
Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
day12---接口和协议
mysql 8.0.12 安装配置方法并--设置修改密码
ArcEngine(二)加载地图文档
dflow入门1——HelloWorld!
品牌方发行NFT时,应如何考量实用性?
Arduino框架下对ESP32 NVS非易失性存储解读以及应用示例
熊市中预言机,牛市中的战斗机,藏宝计划起飞,坐稳扶好!
Logic Pro X built-in sound library list