first post, please be gentle.
Everyone I work with is always encouraging me to switch from MATLAB for post-processing of data to python because of [reasons].
The data that is generated is output into a .txt file which is just a bunch of space delimited numbers, in several rows.
My current code is only this:
> import numpy
>
> filepath='data.txt'
>
>
>
> with open(filepath) as file:
>
> data=[float(s) for s in file.read().split()]
I think what this should do is take care of the space delineator, and get me a list of all the data. Then I can use the number of lines to figure out how to rearrange the list into an array (sidenote: should I just use numpy.loadtxt() to do this?).
The only problem is that some of the numbers in my .txt file are not properly converting to a float. For example, most numbers in the file look something like this "0.900000000E-2", and convert fine. However, a few very small numbers are not written in proper scientific notation and appear as "1.23456789-117." The intended number, is of course 1.23456789E-117.
Matlab has a built in tool on its import function which replaces "unimportable" cells with ____, where ____ can be NaN, or 0, or whatever is appropriate. How do I program something like this into my code which imports the data before I make the call to change all the strings to floats?
Thanks!