I have a text file which contains float characters line by line as
15.723
17.567
I tried reading the file and after doing this
with open('<path_to_file>/writefile.txt', 'r') as fin:
data_read = fin.read()
When I print data_read, I get
'15.723\n17.567\n'
Now I need to save this string into an array containg
float_array[0]=15.723
float_array[1]=17.567
How do I do the conversion?
I tried
print(float(data_read))
res = data_read.astype(float)
print(res)
And I got
ValueError: could not convert string to float: '15.723\n17.567\n'
What am I doing wrong here?
I am expecting something like float_array[0]=15.723 float_array[1]=17.567