0

I have:

arr_1 = tf.random_uniform([3],0.1,0.2)
arr_2 = tf.random_uniform([3],-0.1,0.1)

I am trying to create an arr_3 which has a size of 6 and alternates elements from arr_1 and arr_2. How should I go about this? Since tensors are read-only as such, I don't think I can index them and assign values the same way I would with numpy. Any solutions?

2
  • Why not first do that using numpy and convert arr_3 into tensor? Commented Jun 19, 2018 at 18:06
  • I am doing this inside a map function for an object of the Dataset API. If I use numpy functions, it does not generate a random number of every single call, but instead uses the number it generated in the first call. Commented Jun 19, 2018 at 18:14

1 Answer 1

2

This might work. The idea is based on stacking the data and then flattening it.

arr_3 = tf.reshape(tf.stack([arr_1, arr_2], axis=1), [-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.