2016-11-30 1 views
0

これは私がやろうとしています何theanoなぜ行列とベクトルを連結するのが間違っていますか?

max_max=200 
beReplaced=T.matrix() 
toReplace=T.matrix() 
timeArray=T.arange(max_max) 


def f(v,k,w): 
    return T.concatenate([w[:k],v,w[k+1:]],axis=0) 

result,_=theano.scan(f, 
        sequences=[toReplace,timeArray], 
        outputs_info=beReplaced) 

で私のコードでは、行でtoReplaceラインでbeReplacedを置き換えています。私のやり方は、wconcatenatevlowerの投稿者wの部分です。

vは、toReplaceの行です。ここで

は、エラーレポート

Traceback (most recent call last): 
    File "/Users/qiansteven/Desktop/NLP/RNN/my.py", line 20, in <module> 
    outputs_info=np.zeros((5,5),dtype=np.float64)) 
    File "/usr/local/lib/python2.7/site-packages/theano/scan_module/scan.py", line 745, in scan 
    condition, outputs, updates = scan_utils.get_updates_and_outputs(fn(*args)) 
    File "/Users/qiansteven/Desktop/NLP/RNN/my.py", line 16, in f 
    return T.concatenate([a,b,c],axis=0) 
    File "/usr/local/lib/python2.7/site-packages/theano/tensor/basic.py", line 4225, in concatenate 
    return join(axis, *tensor_list) 
    File "/usr/local/lib/python2.7/site-packages/theano/gof/op.py", line 611, in __call__ 
    node = self.make_node(*inputs, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/theano/tensor/basic.py", line 3750, in make_node 
    axis, tensors, as_tensor_variable_args, output_maker) 
    File "/usr/local/lib/python2.7/site-packages/theano/tensor/basic.py", line 3816, in _make_node_internal 
    raise TypeError("Join() can only join tensors with the same " 
TypeError: Join() can only join tensors with the same number of dimensions. 

何が問題になっていますです???????????

答えて

0

解決策は、v.dimshuffle('x',0)を連結することであり、それは暗い問題を解決します。

0

non_sequencestoReplaceを入れます。それ以外の場合は、タイムステップごとにスライスがかかります。ベクトルと行列を連結しようとすると、Theanoはエラーを報告します。

def f(k,w,v): #NOTE the argument order change 
    return T.concatenate([w[:k],v,w[k+1:]],axis=0) 

result,_=theano.scan(f, 
        sequences=timeArray, 
        outputs_info=beReplaced, 
        non_sequences=toReplace) 
+0

交換するためにスライスを取ることは私の目的であり、変更することはできません。 'toReplace'を' non_sequence'に入れると 'output'の形が変わり、無効になります。 解決策は、 'v.dimshuffle( 'x'、0)'を連結することで、それは暗い問題を解決します。 ありがとうございました。 –

関連する問題