def IntToBinVec(x, v = None):
#If no vector is passed create a new one
if(v is None):
dim = int(np.log2(x)) + 1
v = np.zeros([dim], dtype = np.int)
#v will contain the binary vector
c = 0
while(x > 0):
#If the vector has been filled; return truncating the rest
if c >= len(v):
break
#Test if the LSB is set
if(x & 1 == 1):
#Set the bits in right-to-left order
v[c] = 1
#Onto the next column and bit
c += 1
x >>= 1
return v
#Plot the model R learning the data set A, Y
#R: A regression model
#A: The data samples
#Y: The target vectors
评论列表
文章目录