def partition_data(X, y):
 (Xs, ys) = shuffle_array(X, y)
 mapping = {}
 for i in xrange(len(y)):
  yi = ys[i]
  try:
   mapping[yi].append(i)
  except KeyError:
   mapping[yi] = [i]
 (Xtrain, ytrain) = ([], [])
 (Xtest, ytest) = ([], [])
 for (key, indices) in mapping.iteritems():
  Xtrain.extend([Xs[i] for i in indices[:1]])
  ytrain.extend([ys[i] for i in indices[:1]])
  Xtest.extend([Xs[i] for i in indices[1:20]])
  ytest.extend([ys[i] for i in indices[1:20]])
 return (Xtrain, ytrain, Xtest, ytest)

def partition_data ( X , y ) : ( Xs , ys ) = shuffle_array ( X , y ) mapping = { } for i in xrange ( len ( y ) ) : yi = ys [ i ] try : mapping [ yi ] . append ( i ) except KeyError : mapping [ yi ] = [ i ] ( Xtrain , ytrain ) = ( [ ] , [ ] ) ( Xtest , ytest ) = ( [ ] , [ ] ) for ( key , indices ) in mapping . iteritems ( ) : Xtrain . extend ( [ Xs [ i ] for i in indices [ : 1 ] ] ) ytrain . extend ( [ ys [ i ] for i in indices [ : 1 ] ] ) Xtest . extend ( [ Xs [ i ] for i in indices [ 1 : 20 ] ] ) ytest . extend ( [ ys [ i ] for i in indices [ 1 : 20 ] ] ) return ( Xtrain , ytrain , Xtest , ytest )
shuffles the input data and splits it into a new set of images .