我需要創建一個隨機的整數值串列,這些值代表其他操作的索引,問題是tf.random.uniform可以多次生成相同的值,我不希望這種行為出現。有沒有辦法改變它?
indices = tf.random.uniform(shape=[size_for_layer_submodel[index], ], minval=0,
maxval=size_for_layer[index], dtype=tf.dtypes.int64, seed=seed, name=None)
uj5u.com熱心網友回復:
您想要的是無需更換的采樣。
嘗試這樣的事情。
sorted_indices = tf.range(size_for_layer_submodel[index])
shuffled_indices = tf.shuffle(sorted_indices)
uj5u.com熱心網友回復:
我知道你特別要求tf,但numpy的也有一個功能對于這一點,np.random.choice,這可能使事情變得更清潔。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/351045.html
