当前位置:网站首页>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))
...
边栏推荐
- 【Proteus仿真】74HC154 四线转12线译码器组成的16路流水灯
- 触摸与屏幕自动旋转调试
- ByteDance layoffs, test engineers were almost destroyed: how terrible is the routine behind the recruitment of large factories?
- Qt:qss custom qradiobutton instance
- 今晚要修稿子準備發佈。但是,仍卡在這裡,也許你需要的是一個段子。
- T5 attempt
- In the middle of the year, I have prepared a small number of automated interview questions. Welcome to the self-test
- 我对测试工作的一些认识(资深测试人员总结)
- What is the salary level of 17k? Let's take a look at the whole interview process of post-95 Test Engineers
- 2021 postgraduate entrance examination mathematics 2 linear algebra
猜你喜欢
Game test related tests a hero's skills (spring moves are asked more questions)
The five-year itch of software testing engineers tells the experience of breaking through bottlenecks for two years
Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)
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
What kind of living condition is a tester with a monthly salary of more than 10000?
行业唯一!法大大电子合同上榜36氪硬核科技企业
Activity and fragment lifecycle
Software testing e-commerce projects that can be written into your resume, don't you come in and get it?
My understanding of testing (summarized by senior testers)
面试题总结(2) IO模型,集合,NIO 原理,缓存穿透,击穿雪崩
随机推荐
AMS series - application startup process
Commonly used discrete random distribution
15 software testing Trends Worthy of attention
Software testing redis database
I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it
Communication software development and Application
Internet Socket (非)阻塞write/read n个字节
CorelDRAW Graphics Suite 2022新版功能详情介绍
Hal - General
Have you learned the new technology to improve sales in 2021?
1. Hal driven development
Error installing the specified version of pilot
游戏测试相关 测试一个英雄的技能(春招被问比较多的一道题)
Matlab memory variable management command
做软件测试三年,薪资不到20K,今天,我提出了辞职…
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func mai
redis那些事儿
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
Google Earth Engine(GEE)——GHSL 全球人口网格数据集250米分辨率