add onehot utility function
This commit is contained in:
parent
e7783188bb
commit
39bbf27860
1 changed files with 8 additions and 0 deletions
|
@ -28,6 +28,14 @@ def lower_priority():
|
|||
os.nice(1)
|
||||
|
||||
|
||||
def onehot(y):
|
||||
unique = np.unique(y)
|
||||
Y = np.zeros((y.shape[0], len(unique)), dtype=np.int8)
|
||||
offsets = np.arange(len(y)) * len(unique)
|
||||
Y.flat[offsets + y.flat] = 1
|
||||
return Y
|
||||
|
||||
|
||||
# more
|
||||
|
||||
_log_was_update = False
|
||||
|
|
Loading…
Add table
Reference in a new issue