def to_categorical(y, nb_classes):
 y = np.asarray(y, dtype='int32')
 if (not nb_classes):
  nb_classes = (np.max(y) + 1)
 Y = np.zeros((len(y), nb_classes))
 for i in range(len(y)):
  Y[(i, y[i])] = 1.0
 return Y

def to_categorical ( y , nb_classes ) : y = np . asarray ( y , dtype = 'int32' ) if ( not nb_classes ) : nb_classes = ( np . max ( y ) + 1 ) Y = np . zeros ( ( len ( y ) , nb_classes ) ) for i in range ( len ( y ) ) : Y [ ( i , y [ i ] ) ] = 1.0 return Y
converts a class vector to binary class matrix .