<s> import numpy as np <EOL> def unit_range ( arr , data_min = None , data_max = None , samples_in = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> samplesIn = <NUM_LIT:1> if samples_in == '<STR_LIT>' else <NUM_LIT:0> <EOL> dimsIn = int ( not samplesIn ) <EOL> nSamples = arr . shape [ samplesIn ] <EOL> nDims = arr . shape [ dimsIn ] <EOL> theshape = [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> theshape [ dimsIn ] = nDims <EOL> if data_max is None : <EOL> data_max = arr . max ( axis = samplesIn ) <EOL> if data_min is None : <EOL> data_min = arr . min ( axis = samplesIn ) <EOL> norma = ( arr - data_min . reshape ( theshape ) ) / ( data_max - data_min ) . reshape ( theshape ) <EOL> return norma , data_min , data_max <EOL> def mean_zero ( arr , mean_vector = None , samples_in = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> samplesIn = <NUM_LIT:1> if samples_in == '<STR_LIT>' else <NUM_LIT:0> <EOL> dimsIn = int ( not samplesIn ) <EOL> nSamples = arr . shape [ samplesIn ] <EOL> nDims = arr . shape [ dimsIn ] <EOL> theshape = [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> theshape [ dimsIn ] = nDims <EOL> if not mean_vector : <EOL> mean_vector = arr . mean ( axis = samplesIn ) . reshape ( theshape ) <EOL> amean = arr - mean_vector <EOL> return amean , mean_vector <EOL> def mean_zero_unit_variance ( arr , mean_vector = None , std_vector = None , samples_in = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> samplesIn = <NUM_LIT:1> if samples_in == '<STR_LIT>' else <NUM_LIT:0> <EOL> dimsIn = int ( not samplesIn ) <EOL> nSamples = arr . shape [ samplesIn ] <EOL> nDims = arr . shape [ dimsIn ] <EOL> theshape = [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> theshape [ dimsIn ] = nDims <EOL> if not mean_vector : <EOL> mean_vector = arr . mean ( axis = samplesIn ) . reshape ( theshape ) <EOL> if not std_vector : <EOL> std_vector = arr . std ( axis = samplesIn ) . reshape ( theshape ) <EOL> std_vector [ std_vector < <NUM_LIT> ] = <NUM_LIT:1> <EOL> norma = ( arr - mean_vector ) / std_vector <EOL> return norma , mean_vector , std_vector <EOL> def labels_to_one_hot ( labels ) : <EOL> '''<STR_LIT>''' <EOL> n_samples = len ( labels ) <EOL> dlabels = { } <EOL> ix = <NUM_LIT:0> <EOL> for label in labels : <EOL> if label not in dlabels : <EOL> dlabels [ label ] = ix <EOL> ix += <NUM_LIT:1> <EOL> n_dims = len ( dlabels ) <EOL> arr = np . zeros ( ( n_samples , n_dims ) ) <EOL> for i in xrange ( n_samples ) : <EOL> arr [ i , dlabels [ labels [ i ] ] ] = <NUM_LIT:1.0> <EOL> return arr , dlabels </s>
