5

I need a transformation of a tensor which is very similar to roll. The difference is that I do not want the values from the end of the axis to appear in the beginning. In other words I want, for example, the 2nd element to be on 3d place but I do not want the last element to become the first one. Instead, I want the first elements to be zeros.

I have tried this:

prev_xs = tf.roll(xs, shift = 1, axis = 1)
prev_xs[:,0] = 0.0

However, it does not work because

TypeError: 'Tensor' object does not support item assignment

So, what is the proper solution of the problem?

1 Answer 1

6

You could use

prev_xs = tf.concat((tf.zeros([tf.shape(xs)[0], 1]), xs[:, :1]), axis=1)

Step-by-step, we discard the last column of xs by indexing like [:, :1]. We create a column of zeros with the appropriate number of rows. Then we concatenate it in front of xs, pushing every column back by 1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.