2016-03-15 50 views
0

我用我自己的數據集採用Theano使用此代碼訓練SDA:爲什麼Theano共享變量的輸出是一個數組?

train_set_x = theano.shared(np.asarray(x, type=theano.config.floatX)) 
train_set_y = T.cast(theano.shared(np.asarray(y,dtype=theano.config.floatX)), 'int32') 

然後我打印train_set_x和train_set_y與此代碼:

for x,y in zip(train_set_x.get_value(), train_set_y.eval()): 
    print ("x=", x) 
    print ("y=", y) 

這些都是我的結果:

('x=', array([ 1., 0.36037669, 0., 0.06552909, 0.46260971,0.45968048,.27107092, 0.16942367, 0.09178392, 0.35540537, 0.38170689, 0.1973381 , 0.22643969])) 
('y=', 0) 

正如你所看到的輸出是一個numpy數組。然而,當我打印由theano教程提供了SdK.py的MNIST數據集,通過這些代碼:

datasets = load_data(dataset) 

train_set_x, train_set_y = datasets[0] 
valid_set_x, valid_set_y = datasets[1] 
test_set_x, test_set_y = datasets[2] 

for x,y in zip(train_set_x.get_value(), train_set_y.eval()):    
    print ("x=", x)              
    print ("y=", y) 

我看到這些結果:

x= [ 0.   0.   0.   0.   0.   0.   
    0.0703125 0.0703125 0.0703125 0.4921875 0.53125  0.68359375 
    0.1015625 0.6484375 0.99609375 0.96484375 0.49609375 0.   ... 

正如你可以看到這是不是一個numpy的陣列。你有什麼想法,我怎樣才能以我的輸出看起來像Theano教程輸出的方式修復我的代碼和數據集?

回答

0

看起來Theano教程是用Python3編寫的,而且您使用的是Python 2.x.

要獲得與Python 2 x相同的輸出格式,您可以在print後刪除括號。

a = numpy.asarray([1,2,3]) 
print ("x=", a) # this will output ('x=', array([1, 2, 3])) 
print "x=", a # this will output x= [1 2 3] 
相關問題