2017-01-01 12 views
0

私は2つのテンソルがありますテンソルを1つクローン化して3次元テンソルを連結しますか?

a = tf.placeholder(tf.float32, [None, 20, 100]) 
b = tf.placeholder(tf.float32, [None, 1, 100]) 

私はa[i, 20, 100]bを追加したい、などcとしてcを作成するには、[None, 20, 200]の形状を有しています。

これはかなり単純そうですが、私はtf.concatでこれを行う方法を考え出したていない:

tf.concat(0, [a, b]) -> Shapes (20, 100) and (1, 100) are not compatible 
tf.concat(1, [a, b]) => shape=(?, 28, 100) which is not what I wanted 
tf.concat(2, [a, b]) -> Shapes (?, 20) and (?, 1) are not compatible 

私はCONCAT、その後ab最初の形状を変更する必要がありますか?

+0

あなたはtf.concat' – martianwars

答えて

1

これは、tf.tileを使用して行うことができます。 クローンテンソルに沿って次元1、20回する必要がありますaと互換性があります。次に、次元2に沿った単純な連結が結果を返します。

はここで、完全なコードです

import tensorflow as tf 

a = tf.placeholder(tf.float32, [None, 20, 100]) 
b = tf.placeholder(tf.float32, [None, 1, 100]) 
c = tf.tile(b, [1,20,1]) 
print c.get_shape() 
# Output - (?, 20, 100) 
d = tf.concat(2, [a,c]) 
print d.get_shape() 
# Output - (?, 20, 200) 
+0

どうもありがとうございました ''前tf.tile'を使用する必要があります!実際に私が 'a'の第二次元を知らないのであれば、私は何をしますか?すなわち、a = tf.placeholder(tf.float32、[None、None、100]); b = tf.placeholder(tf.float32、[なし、1,100]) '。 'tf.tile'は引数に' int32/64'型が必要です。 – Blue482

+1

'tf.unpack(tf.shape(a))[1]'を使って解決しました! :) 再度、感謝します – Blue482

関連する問題