例子
来自数组:
[ 8.85145037e+02 -1.24294207e+02 -1.42830519e+01 -8.62776672e+01 -8.66725361e+01 -7.96623643e+00 1.23582408e+01 2.84470918e+01 ]
列出:
[[885.1450370958278],[-124.29420748608811],[-14.283051875003691],[-86.27766716541419],[-86.67253605552324],[-7.966236427390702],[12.358240800052027],[28.447091751843175]]
使用tolist()时,结果为:
[885.1450370958278, -124.29420748608811, -14.283051875003691, -86.27766716541419, -86.67253605552324, -7.966236427390702, 12.358240800052027, 28.447091751843175]
提前致谢
如果您确实需要像这样嵌套列表,则可以执行以下操作:
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]]
但x.tolist()
也是一个列表。