osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to split a list type array into float array?


On Tue, May 21, 2019 at 03:38:43AM -0700, Madhavan Bomidi wrote:
> Hi,
> 
> I have the following list type data:
> 
> ['  29.7963   29.6167   29.4371   29.2574   29.0778   28.8982   28.7185   28.5389   28.3593   28.1797   28.0000   27.8204   27.6408   27.4611   27.2815   27.1019   26.9223   26.7426   26.5630   26.3834   26.2037   26.0241   25.8445   25.6649   25.4852   25.3056   25.1260   24.9463   24.7667   24.5871   24.4075   24.2278   24.0482   -0.2616   -0.3215   -0.3813   -0.4412\n']
> 
> Can anyone help me split as a float array?

did you mean

s = ['   29.79... ...\n']
f = [float(f) for f in s[0].strip().split()]


and start to read the docs?

https://docs.python.org/3/library/stdtypes.html?highlight=split#str.split
https://docs.python.org/3/tutorial/datastructures.html?highlight=list

and so on...


a.