I am working on a algorithm with tensorflow.
Following is the NumPy version of the wanted code:
x = [1,2,3,4,5,6,7,8,9,10]
sets = {1,5,7}
y = [0,0,0,0,0,0,0,0,0,0]
for i in range(10):
if i in sets:
y[i] = x[i]
which gets the result:
y = [0,2,0,0,0,6,0,8,0,0]
How to implement this in tensorflow?
Is there any way to to implement this in tensorflow using the same logic, not by converting NumPy arrays to tensor after the calculation, but instead doing all the operation using tensor (e.g. using tensor to index the tensor, and assign its value by x(tensor) if the index is in the set).