当前位置:网站首页>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))...
边栏推荐
- 1. Hal driven development
- 11. Provider service registration of Nacos service registration source code analysis
- Solutions of n-ary linear equations and their criteria
- Qt:qss custom qradiobutton instance
- 2021 reading summary (continuously updating)
- php服务器 与redis交互大量CLOSE_WAIT分析
- Do you really need automated testing?
- 如何:配置 ClickOnce 信任提示行为
- Have you learned the new technology to improve sales in 2021?
- What experience is there only one test in the company? Listen to what they say
猜你喜欢

How did I grow up in the past eight years as a test engineer of meituan? I hope technicians can gain something after reading it

解决undefined reference to `__aeabi_uidivmod‘和undefined reference to `__aeabi_uidiv‘错误

AIDL

The element form shows the relationship between elementary transformation and elementary matrix

Qt:qss custom qscrollbar instance

面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩

行业唯一!法大大电子合同上榜36氪硬核科技企业

QT: QSS custom qtreeview instance

嵌入式软件测试怎么实现自动化测试?

Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡
随机推荐
8年测试总监的行业思考,看完后测试思维认知更深刻
(二)进制
Qt:qss custom qpprogressbar instance
Stack, monotone stack, queue, monotone queue
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it
Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
Clion debug
如何成为一名高级数字 IC 设计工程师(1-2)Verilog 编码语法篇:Verilog 1995、2001、2005 标准
AMS series - application startup process
读书笔记:《心若菩提》 曹德旺
ConstraintLayout跟RelativeLayout嵌套出现的莫名奇妙的问题
Solve the problem that pycharm Chinese input method does not follow
字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?
触摸与屏幕自动旋转调试
What are the strengths of "testers"?
VPP三层网络互联配置
嵌入式軟件測試怎麼實現自動化測試?
The five-year itch of software testing engineers tells the experience of breaking through bottlenecks for two years
Hard goods | write all the codes as soon as you change the test steps? Why not try yaml to realize data-driven?