I am currently getting:
y=[[ 0.16666667]
[-0.16666667]
[ 0.16666667]]
This comes out of a function im using and i need to turn the above into a list in the format below:
x= [0.16666667,-0.16666667,0.16666667]
I tried list(y) but this does not work, because it returns:
[array([ 0.16666667]), array([-0.16666667]), array([ 0.16666667])]
How exactly would I do this??
my_list = [col for row in matrix for col in row]
You can use the numpy .tolist()
method:
array.tolist()
There is also one more advantage to it... It works with matrix
objects, the list comprehension doesn't. If you want to remove the dimension first you can use numpy methods to do so, such as array.squeeze()
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