Is it possible to transform a 1D tensor to a list ?
thank you
To convert back from tensor to numpy array you can simply run . eval() on the transformed tensor.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With