2016-03-15 143 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] 
相关问题