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

kamfulebu
  • 229
  • 1
  • 3
  • 11

1 Answers1

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.

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214