Reputation: 1409
I am trying to use the tensorflow map function but I am stuck at an indexing problem.
In simple python, I am trying to do the following operation:-
for i in range(1,25):
u [i] = uold [i] - K * ( uold [i] - uold [i-1] )
In tensorflow, I am encountering an indexing issue due to "(uold1[i]-uold1[i-1])". Currently I have written the statement as:-
u = tf.map_fn ( lambda u: uold - K * ( uold - uold ), uold )
In the current equation the second term is always zero. I am not sure how to change it to get the desired output.
Upvotes: 0
Views: 91
Reputation: 748
You probably want to create a tensor that shifts to right by one dimension (using tf.pad()) instead, and then calculate the difference. Ex.
temp = uold_shifted_to_right - K * (uold - uold_shifted_to_right)
Then take out the first column from temp (using tf.slice()).
Upvotes: 1