python - How to convert array to list? -


this question has answer here:

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 () result is:

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

thanks in advance

if need list nested that, 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() list.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -