当前位置:网站首页>One hot code
One hot code
2022-07-03 11:14:00 【vanguard】
Fever alone /one-hot It is used to represent a special byte or vector in digital circuits and machine learning ,
Intuitively speaking, there are as many bits as there are states , And only one bit is 1, For all other 0 A code system of .
Only one bit of this byte or vector is allowed to be 1, All other bits must be 0.
It is called the sole heat because there can only be one 1, If the opposite is true , only one 0, Others are 1, Is called alone cold (one-cold).
In statistics , Dummy variables represent similar concepts .
Usually , In the communication network protocol stack , Use 8-bit or 16 bit state unique hot code , And the system occupies one of the status codes , The rest can be used by users .
import numpy as np
wide = 10
test = np.random.randint(wide,size=5)
print(test)
# raw
def one_hot(num,wide):
res = np.zeros(wide)
res[num] = 1
return res
print(np.array([one_hot(i,wide) for i in test]))
# batch
def one_hots(narr,wide):
res = np.zeros((narr.size,wide))
row = np.arange(narr.size)
res[row, narr] = 1
return res
print(one_hots(test,wide))
# multi-hot
test = np.array([[1,2,3,4,5],[7,8,9,0,1]])
print(np.array([one_hots(i,wide).sum(axis=0) for i in test]))
# tensorflow
import tensorflow as tf
print(tf.keras.utils.to_categorical(test,num_classes=(wide)))
# ...
from sklearn.preprocessing import LabelBinarizer
print(LabelBinarizer().fit(np.arange(wide)).transform(test))
# OneHotEncoder ...
# pandas
# import pandas as pd
# print(pd.get_dummies(test,wide))
...
边栏推荐
- Internet Socket (非)阻塞write/read n个字节
- Typescript learning summary
- 封装一个koa分布式锁中间件来解决幂等或重复请求的问题
- What kind of living condition is a tester with a monthly salary of more than 10000?
- 【Proteus仿真】74HC154 四线转12线译码器组成的16路流水灯
- 做软件测试三年,薪资不到20K,今天,我提出了辞职…
- My understanding of testing (summarized by senior testers)
- 8年测试总监的行业思考,看完后测试思维认知更深刻
- Qt:qss custom qpprogressbar instance
- Ext file system mechanism principle
猜你喜欢
有赞CTO崔玉松:有赞Jarvis核心目标是使产品变得更加聪明和可靠
高精度室内定位技术,在智慧工厂安全管理的应用
Game test related tests a hero's skills (spring moves are asked more questions)
Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
Solution: jupyter notebook does not pop up the default browser
I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
Error installing the specified version of pilot
ByteDance layoffs, test engineers were almost destroyed: how terrible is the routine behind the recruitment of large factories?
Probability theory: application of convolution in calculating moving average
英特尔13代酷睿旗舰曝光,单核5.5GHz
随机推荐
2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func mai
QT: QSS custom qtoolbutton instance
Basic usage of sqlmap
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
Qt:qss custom qspinbox instance
QT: QSS custom qtableview instance
Oracle收回权限 & 创建角色
POI excel 单元格换行
Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)
Imread change image display size
10. Nacos source code construction
QT: QSS custom qtabwidget and qtabbar instances
Qt:qss custom qradiobutton instance
如何成为一名高级数字 IC 设计工程师(1-2)Verilog 编码语法篇:Verilog 1995、2001、2005 标准
How to realize automatic testing in embedded software testing?
Matlab memory variable management command
线性表的双链表
Cause: org. apache. ibatis. builder. Builderexception: error parsing SQL mapper configuration problem analysis
历经一个月,终于拿到金蝶Offer!分享一下四面面经+复习资料
触摸与屏幕自动旋转调试