#NEWLINE# def one_hot( x , n ) : #NEWLINE# #INDENT# if ( type ( x ) == list ) : #NEWLINE# #INDENT# x = np . array ( x ) #NEWLINE# #UNINDENT# x = x . flatten ( ) #NEWLINE# o_h = np . zeros ( ( len ( x ) , n ) ) #NEWLINE# o_h [ ( np . arange ( len ( x ) ) , x ) ] = 1 #NEWLINE# return o_h