当前位置:网站首页>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))...
边栏推荐
- Qt:qss custom qlistview instance
- MAUI Developer Day in GCR
- 值得关注的15种软件测试趋势
- Error installing the specified version of pilot
- 做软件测试三年,薪资不到20K,今天,我提出了辞职…
- QT: QSS custom qtabwidget and qtabbar instances
- glassfish org. h2.server. Shutdownhandler classnotfoundexception exception exception handling
- Software testing (test case) writing: vulgar, native and skillful
- 线性表的双链表
- Solution: jupyter notebook does not pop up the default browser
猜你喜欢
随机推荐
如何让让别人畏惧你
11. Provider service registration of Nacos service registration source code analysis
Is pinduogai's sales safe in 2022?
表空间创建管理及控制文件管理
数据库增量备份 - DB INCR DB FULL
Have you learned the new technology to improve sales in 2021?
Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
Hal - General
EPS电动转向系统分析
Qt:qss custom qstatusbar instance
字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?
What experience is there only one test in the company? Listen to what they say
Software testing redis database
Commonly used discrete random distribution
Software testing (test case) writing: vulgar, native and skillful
Qt:qss custom qmenubar instance
封装一个koa分布式锁中间件来解决幂等或重复请求的问题
POI excel 单元格换行
2. Hal hardware abstraction layer
行业唯一!法大大电子合同上榜36氪硬核科技企业









