2017-05-16 12 views
0

2次元テンソルAの形状は(m、n)ですが、mとnは不明です。例えばA = [[1,2,3]、[4,5,6]]、ここではm = 2、n = 3である。私の操作の後、私はB = [[1,20,3]、[4,5,60]]にしたい。操作は次のようである:6,5,4,3,2,1TensorFlowで動的次元を持つ2次元テンソルの要素を操作する方法

2)6を選択し、行2及びCOL 3占有されることを意味:降順とに

1)ソートすべての要素;

3)行2または列3がすでに占有されているため、5,4および3をスキップします。

4)行1と列2が占有されていないため2を選択します。

5)ストップ、すべての行)は、全てのcolsについても同様に(

6)選択された要素*を占有しているので、10

答えて

0

ガットの答えは私の友人と協議した後:

A=A-tf.reduce_min(A) 
mask=A*0 

def body(x,mask): 
a=x-tf.reduce_max(x) 
a=tf.sign(a)+1 
mask=mask+a 
where = tf.equal(x, tf.reduce_max(x)) 
indices = tf.where(where) 
indices = tf.cast(indices, "int32") 
col_slice=tf.slice(x, [0, indices[0][1]], [-1, 1]) 
col_slice=col_slice-tf.reduce_max(col_slice) 
col_slice=-tf.sign(col_slice) 
col_slice = tf.reshape(col_slice, [-1]) 
b=tf.matmul(tf.diag(col_slice),x) 
row_slice=tf.slice(x, [indices[0][0],0], [1,-1]) 
row_slice=row_slice-tf.reduce_max(row_slice) 
row_slice=-tf.sign(row_slice) 
row_slice=tf.reshape(row_slice,[-1]) 
c=tf.matmul(b,tf.diag(row_slice)) 
return (c,mask) 

def cond(x,mask): 
return tf.greater(tf.reduce_sum(x),0) 

_,final_mask=tf.while_loop(cond, body,(A,mask)) 
final_mask=final_mask*9+1 
B=A*final_mask 
関連する問題