8

Is it possible to transform a 1D tensor to a list ?

thank you

David
  • 155
  • 2
  • 6
  • 2
    Have a look at this answer: https://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow - it is relatively straightforward to convert to an array, from which you can use `list()` to convert to a list – 4Oh4 Nov 27 '17 at 13:09
  • Thank you ! I didn't see this question – David Nov 27 '17 at 13:11
  • 1
    Possible duplicate of [How can I convert a tensor into a numpy array in TensorFlow?](https://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow) – Sunreef Nov 27 '17 at 13:13

1 Answers1

12
l = tf.Variable([0, 1, 2, 3]).numpy().tolist()
type(l)
>>> list

l
>>> [0, 1, 2, 3]

This method lets convert to list not only 1D tensor, but also any other shape

MariaMsu
  • 344
  • 4
  • 10