2017-09-01 18 views
1

を放送割り当てるtensorflowのいずれかの方法は、現在のソリューションは、他のすべてのを繰り返すかもしれない私のために行列に放送割り当て(tf.Variable)次のコードのような 何か....tensorflow変数は

a = tf.Variable(np.zeros([10,10,10,10], np.int32)) 

# creating a mask and trying to assign the 2nd, 3rd dimension of a 
mask = tf.ones([10,10]) 

# 1) which is work in this case, but only assign one block 
op = a[0,:,:,0].assign(mask) 

# 2) attempting to broadcasting while not work, size mismatch 
op = a[0].assign(mask) 

を達成することができています1) のようにネストされたループに悩まされているかもしれません。

答えて

0

ない一般解(ハードコードさテンソル形状のたくさん)、うまくいけば、これはあなたの例要旨示します:

a = tf.Variable(np.zeros([10,10,10,10], np.int32)) 
mask = tf.ones([10,10],dtype=tf.int32) 
mask_reshaped = tf.reshape(mask,[1,10,10,1]) # make the number of dims match 
mask_broadcast = tf.tile(mask_reshaped, [10, 1, 1, 10]) # do the actual broadcast 
op = a.assign(mask_broadcast) 
+0

素敵な何かトリックを!ありがとう!それは本当にきれいです。 –

関連する問題