Home > Blockchain >  iterating over/broadcast_to tensorflow tensors
iterating over/broadcast_to tensorflow tensors

Time:09-12

Consider the following two tensors

t1=tf.convert_to_tensor([1, 2]) and

t2=tf.convert_to_tensor([3,7.2,4,3,8])

the result of t1 t2 by tf.broadcast or any other method (other than conversion to numpy) shall be

result = ( [3, 7.2, 4, 3, 8, 6, 14.4, 8, 6, 16 ], dtype = float32)

Thanks in advance.

CodePudding user response:

Maybe something like this:

import tensorflow as tf

t1=tf.convert_to_tensor([1.0, 2.0])

t2=tf.convert_to_tensor([3,7.2,4,3,8])

tf.reshape(t2*t1[:, None], [-1])
<tf.Tensor: shape=(10,), dtype=float32, numpy=
array([ 3. ,  7.2,  4. ,  3. ,  8. ,  6. , 14.4,  8. ,  6. , 16. ],
      dtype=float32)>
  • Related