Python: numpy delimited array

I have an array created by numpy that looks like this:

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

How do I convert this to a list? So it looks like this:

['54 .51399994 ',' - 12.10200024 ',' - 11.88099957 ']
['56 .23899841 ',' - 8.30799961 ',' - 2.03500009 ']

+4
source share
1 answer

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

import numpy as np arr=np.array([ ( 54.51399994, -12.10200024, -11.88099957), ( 56.23899841, -8.30799961, -2.03500009)]) print(arr.astype('|S10')) 

gives

 [['54.51399994', '-12.10200024', '-11.88099957'], ['56.23899841', '-8.30799961', '-2.03500009']] 
+5
source

Source: https://habr.com/ru/post/1379289/


All Articles