#NEWLINE# def encode_classifications( class_list ) : #NEWLINE# #INDENT# '\n    Given a list of class labels, encodes the list in a manner that is usable in neural networks. For each sample,\n    there will be a list of 0s and one 1 corresponding to the label that sample is encoded. Also returns the list of\n    so that encoded sample lists can be decoded.\n    :param class_list: List of labels, that can be either strings or numbers.\n    :return: classes: List of strings denoting the different labels found in the list.\n        encoded: Numpy array of encoded labels. One row for each sample, with the numbers in the row corresponding to\n            the label for that sample.\n    ' #NEWLINE# classes = [ ] #NEWLINE# for i in class_list : #NEWLINE# #INDENT# if ( i not in classes ) : #NEWLINE# #INDENT# classes . append ( i ) #NEWLINE# #UNINDENT# #UNINDENT# encoded = [ ( [ 0 ] * len ( classes ) ) for i in range ( len ( class_list ) ) ] #NEWLINE# for ( e , i ) in enumerate ( class_list ) : #NEWLINE# #INDENT# encoded [ e ] [ classes . index ( i ) ] = 1 #NEWLINE# #UNINDENT# return ( classes , np . array ( encoded ) )