def encode_labels(labels, nclass=5):
 Y = np.zeros((len(labels), nclass)).astype('float32')
 for (j, y) in enumerate(labels):
  for i in range(nclass):
   if ((i + 1) == (np.floor(y) + 1)):
    Y[(j, i)] = (y - np.floor(y))
   if ((i + 1) == np.floor(y)):
    Y[(j, i)] = ((np.floor(y) - y) + 1)
 return Y

def encode_labels ( labels , nclass = 5 ) : Y = np . zeros ( ( len ( labels ) , nclass ) ) . astype ( 'float32' ) for ( j , y ) in enumerate ( labels ) : for i in range ( nclass ) : if ( ( i + 1 ) == ( np . floor ( y ) + 1 ) ) : Y [ ( j , i ) ] = ( y - np . floor ( y ) ) if ( ( i + 1 ) == np . floor ( y ) ) : Y [ ( j , i ) ] = ( ( np . floor ( y ) - y ) + 1 ) return Y
label encoding from tree lstm paper .