python切分数字放入数组,的Python:拆分numpy的数组

I have an array produced by numpy which looks as follows:

[ 54.51399994 -12.10200024 -11.88099957]

[ 56.23899841 -8.30799961

-2.03500009]

How do i convert this to a list? So it looks as follows:

['54.51399994','-12.10200024','-11.88099957']

['56.23899841','-8.30799961','-2.03500009']

解决方案

You could use astype() to create a new array of string dtype:

import numpy as np

arr=np.array([

( 54.51399994, -12.10200024, -11.88099957),

( 56.23899841, -8.30799961, -2.03500009)])

print(arr.astype('|S10'))

yields

[['54.51399994', '-12.10200024', '-11.88099957'], ['56.23899841', '-8.30799961', '-2.03500009']]

你可能感兴趣的:(python切分数字放入数组)