2017-01-16 5 views
0

Tensorflowでは、もう1つの列から2Dテンソルの1つの列を減算したいと考えています。私はtf.split()またはtf.slice()を使って2テンソルに分割して引くことを見ましたが、これは不必要に複雑に思えました。私の現在のアプローチは、列を-1つの列を乗算して、reduce_sumすることです:Tensorflowテンソルの列を引く

input = tf.constant(
     [[5.8, 3.0], 
     [4.0, 6.0], 
     [7.0, 9.0]]) 
oneMinusOne = tf.constant([1., -1.]) 
temp = tf.mul(input, oneMinusOne) 
delta = tf.reduce_sum(temp, 1) 

はまだ不必要に複雑そうです。これを行う簡単な方法はありますか?

答えて

1

ロットのnumpyは、TensorFlowで期待通りに配列のインデックスを作成します。次の作品:

input = tf.constant(
    [[5.8, 3.0], 
    [4.0, 6.0], 
    [7.0, 9.0]]) 
sess = tf.InteractiveSession() 
ans = input[:, :1] - input[:, 1:] 
print(ans.eval()) 

array([[ 2.80000019], 
    [-2.  ], 
    [-2.  ]], dtype=float32) 
関連する問題