'Create a consecutive set of indices in Tensorflow/Keras
I am using the 'tf.tensor_scatter_nd_update' function to update a Tensor. Update Parameter (update_vals) has dimension of [1,32] and output dimension is [1,12,12,32]. I would like to update a specific location of output which looks like below -
output = tf.tensor_scatter_nd_update(output, indices=[[[0,i,j,0:32]]], updates=update_vals)
But indices=[[[0,i,j,0:32]]] is not allowed to create a consecutive set of indices. What I want to create is indices = [[[0,i,j,0],[0,i,j,1], and so on till [0,i,j,31]]]
Currently I am using for loop to do the same task -
for k in range(32):
update_val = tf.slice(update_vals, begin=[0,k],size=[1,1])
output = tf.tensor_scatter_nd_update(output, indices=[[[0,i,j,k]]], updates=update_val) #Start from here. How to get a value of a tensorl
Is there any way I can get rid of the for loop?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
