Search code examples
pythontensorflow

How to get the value from ListWrapper to create a List


I got one question about how to get the value from ListWrapper to create a List which only includes values.

For example:

lista=[]

costs_list=[<tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>, <tf.Tensor: shape=(), dtype=float32, numpy=69.561775>]


lista+=costs_list
(The value above is different but it is only example to describe the data )


lista=ListWrapper([711.7442, 711.7316, 711.72046, 711.7249, 711.7319, 711.7421, 711.7345, 711.7426, 711.7382, 711.73956, 711.73334, 711.7312, 711.74, 711.7226, 711.7358, 711.7273, 711.7278, 711.7344, 711.7327, 711.73346, 711.73267, 711.7434])

I would like to get List

[711.7442, 711.7316, 711.72046, 711.7249, 711.7319, 711.7421, 711.7345, 711.7426, 711.7382, 711.73956, 711.73334, 711.7312, 711.74, 711.7226, 711.7358, 711.7273, 711.7278, 711.7344, 711.7327, 711.73346, 711.73267, 711.7434]

I tried to use list(lista) but in the end I still got the same result as ListWrapper.

How can I convert the ListWarapper to List or could I use any method to get the value to create a List?

1.use listb=list(lopv for lopv in lista) to convert ListWrapper to List

2.listc=[scaler_v2 for scaler_v2 in listb]


Solution

  • list_values = [float(tensor.numpy()) for tensor in lista]