<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import tensorflow as tf <EOL> import input_data <EOL> mnist = input_data . read_data_sets ( "<STR_LIT>" , one_hot = True ) <EOL> Xtr , Ytr = mnist . train . next_batch ( <NUM_LIT> ) <EOL> Xte , Yte = mnist . test . next_batch ( <NUM_LIT:200> ) <EOL> Xtr = np . reshape ( Xtr , newshape = ( - <NUM_LIT:1> , <NUM_LIT> * <NUM_LIT> ) ) <EOL> Xte = np . reshape ( Xte , newshape = ( - <NUM_LIT:1> , <NUM_LIT> * <NUM_LIT> ) ) <EOL> xtr = tf . placeholder ( "<STR_LIT:float>" , [ None , <NUM_LIT> ] ) <EOL> xte = tf . placeholder ( "<STR_LIT:float>" , [ <NUM_LIT> ] ) <EOL> distance = tf . reduce_sum ( tf . abs ( tf . add ( xtr , tf . neg ( xte ) ) ) , reduction_indices = <NUM_LIT:1> ) <EOL> pred = tf . arg_min ( distance , <NUM_LIT:0> ) <EOL> accuracy = <NUM_LIT:0.> <EOL> init = tf . initialize_all_variables ( ) <EOL> with tf . Session ( ) as sess : <EOL> sess . run ( init ) <EOL> for i in range ( len ( Xte ) ) : <EOL> nn_index = sess . run ( pred , feed_dict = { xtr : Xtr , xte : Xte [ i , : ] } ) <EOL> print "<STR_LIT>" , i , "<STR_LIT>" , np . argmax ( Ytr [ nn_index ] ) , "<STR_LIT>" , np . argmax ( Yte [ i ] ) <EOL> if np . argmax ( Ytr [ nn_index ] ) == np . argmax ( Yte [ i ] ) : <EOL> accuracy += <NUM_LIT:1.> / len ( Xte ) <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" , accuracy </s>
