簡體   English   中英

為什么Theano共享變量的輸出是數組?

[英]Why the output of Theano shared variable is an array?

我正在使用自己的數據集使用Theano使用以下代碼來訓練SdA:

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教程輸出的方式來修復代碼和數據集?

Theano教程似乎是用Python3編寫的,並且您正在使用Python2.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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM