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

边栏推荐
- pytorch one-hot 小技巧
- uniapp swiper 卡片轮播 修改指示点样式效果demo(整理)
- QImage的指针问题
- Using pipreqs export requirements needed for the project. TXT (rather than the whole environment)
- ArcEngine(三)通过MapControl控件实现放大缩小全图漫游
- 001-进程与线程
- ArcEngine(五)用ICommand接口实现放大缩小
- LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
- HCIP练习03(重发布)
- 并发之ReentrantLock
猜你喜欢
随机推荐
服务器资源监控工具-nmon、nmon_analyser
线程介绍与使用
swiper分类菜单双层效果demo(整理)
ArcEngine (3) zoom in and zoom out through the MapControl control to achieve full-image roaming
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
How does Mysql query two data tables for the same fields in two tables at the same time
AI mid-stage sequence labeling task: three data set construction process records
并发之ReentrantLock
uni-app 顶部选项卡吸附效果 demo(整理)
手把手教你如何自制目标检测框架(从理论到实现)
mysql的innodb存储引擎和myisam存储引擎的区别
开发工具之版本控制
Redis集群概念与搭建
pytorch one-hot 小技巧
长短期记忆网络 LSTM
【收获合辑】k-NN与检索任务的异同+jupyter转pdf
积分商城系统设计
Logic Pro X自带音色库列表
redis键值出现 xacxedx00x05tx00&的解决方法
Charles抓包工具学习记录









