当前位置:网站首页>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))...
边栏推荐
- Matlab memory variable management command
- 8年测试总监的行业思考,看完后测试思维认知更深刻
- 1. Hal driven development
- 2021 reading summary (continuously updating)
- 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
- QT: QSS custom qtoolbar and qtoolbox instances
- Overview of testing theory
- Have you learned the new technology to improve sales in 2021?
- T5 attempt
- Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
猜你喜欢

How can UI automated testing get out of trouble? How to embody the value?

My understanding of testing (summarized by senior testers)

Solution: jupyter notebook does not pop up the default browser

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

Multiple IO transfer - preamble

Qt:qss custom qscrollbar instance

Game test related tests a hero's skills (spring moves are asked more questions)

字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?

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

Tencent micro app to get wechat user information
随机推荐
线性表的双链表
英特尔13代酷睿旗舰曝光,单核5.5GHz
1. Hal driven development
8年测试总监的行业思考,看完后测试思维认知更深刻
程序进程管理工具-go supervisor
面试题总结(2) IO模型,集合,NIO 原理,缓存穿透,击穿雪崩
I have been doing software testing for three years, and my salary is less than 20K. Today, I put forward my resignation
15 software testing Trends Worthy of attention
嵌入式軟件測試怎麼實現自動化測試?
Do you really need automated testing?
Qt:qss custom qmenu instance
Multiple IO transfer - preamble
可以写进简历的软件测试电商项目,不进来get一下?
2. Hal hardware abstraction layer
Inexplicable problems in the nesting of constraintlayout and relativelayout
如何清理v$rman_backup_job_details视图 报错ORA-02030
Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率
Logstash backup tracks the data records reported
UI自动化测试如何走出困境?价值又如何体现?
Differences among norm, normalize and normalized in eigen