 # Update random value of tensor using random indices

So, i have a list that contain some seed generated from somewhere else.

I need to use those seed to create a list of random indeces and then create a new tensor with 0 everywhere except for those indeces.

For now the code is like so:

``````for index in [1,3,5]:
seed = 1254 #Only for testing now
#Tensor with X elements all 0s
tensor_testing = tf.zeros([size_for_layer[index],], tf.float32)
#Tensor with Y random generated indices
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)

#Same dimension as indices with the new value
values = tf.fill([tf.shape(indices), ], 15.4)
#start the update
tensor_testing = tf.tensor_scatter_nd_update(tensor_testing, indices, values)
result[index] = tf.reshape(tensor_testing, shape_for_layer[index])
``````

But i get this error:
`ValueError: Dimensions [6,1) of input[shape=] = [] must match dimensions [0,1) of updates[shape=] = : Shapes must be equal rank, but are 0 and 1 for '{{node TensorScatterUpdate}} = TensorScatterUpdate[T=DT_FLOAT, Tindices=DT_INT64](zeros, random_uniform, Fill)' with input shapes: , , .`

I have actually solved the problem like so:

``````for index in [1,3,5]:
seed = 1254 #Only for testing now
#Tensor with X elements all 0s
tensor_testing = tf.zeros(size_for_layer[index], tf.float32)
# Tensor with Y random generated indices
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)

values = tf.fill([tf.shape(tensor_testing), ], 15.4)
tensor_testing = tf.tensor_scatter_nd_update(tensor_testing, tf.expand_dims(indices, 1),
tf.gather(values, indices))

result[index] = tf.reshape(tensor_testing, shape_for_layer[index])
``````

Is there a way to make `tf.random.uniform` generate values with no duplicates?

Are you looking for something like: