Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to transform an 1D tensor to a list ? (Tensorflow)

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

thank you

like image 528
David Avatar asked Nov 27 '17 13:11

David


People also ask

How do you turn a tensor into an array?

To convert back from tensor to numpy array you can simply run . eval() on the transformed tensor.

How do you flatten a tensor in TensorFlow?

To flatten the tensor, we're going to use the TensorFlow reshape operation. So tf. reshape, we pass in our tensor currently represented by tf_initial_tensor_constant, and then the shape that we're going to give it is a -1 inside of a Python list.

Can you slice tensors?

You can use tf. slice on higher dimensional tensors as well. You can also use tf. strided_slice to extract slices of tensors by 'striding' over the tensor dimensions.


1 Answers

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

like image 188
MariaMsu Avatar answered Oct 29 '22 06:10

MariaMsu