2

Examples

from array:

[  8.85145037e+02  -1.24294207e+02  -1.42830519e+01  -8.62776672e+01
  -8.66725361e+01  -7.96623643e+00   1.23582408e+01   2.84470918e+01 ]

to list:

[[885.1450370958278],[-124.29420748608811],[-14.283051875003691],[-86.27766716541419],[-86.67253605552324],[-7.966236427390702],[12.358240800052027],[28.447091751843175]]

When using tolist () the result is:

 [885.1450370958278, -124.29420748608811, -14.283051875003691, -86.27766716541419, -86.67253605552324, -7.966236427390702, 12.358240800052027, 28.447091751843175]

Thanks in advance

2
  • This is already a list... Commented Jan 5, 2016 at 23:37
  • I need a list in which the number will be separate brackets Commented Jan 5, 2016 at 23:39

1 Answer 1

8

If you really need the list to be nested like that, you can do:

In [2]: x
Out[2]: array([ 0. ,  0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5,  5. ])

In [3]: x.reshape(-1, 1).tolist()
Out[3]: [[0.0], [0.5], [1.0], [1.5], [2.0], [2.5], [3.0], [3.5], [4.0], [4.5], [5.0]]

but x.tolist() is also a list.

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Thank you @Waren Weckesser!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.