Function adas.strlist2array
def strlist2array(inlist, n=None)
-
Convert a list of strings containing numbers, typically from an adf file, to a numpy array.
Parameters
inlist
:list
- a list of strings.
n
:int
, optional- break the line at every nth position.
Returns
data
:float
- a numpy 1D array of floats.
Notes
The routine recognizes the D scientific format from fortran, 1.23D+02.
If n is set, split each line at every nth position since some fortran outputs do not leave any space between numbers.
Inverse routine of array2strlist.
Version History
-
Martin O'Mullane, 16-11-2019
- First version
-
Martin O'Mullane, 17-08-2021
- Add option to split on nth character.
Example
>>> import adas as adas >>> lines = ['2.30e+00 5.50e+00 8.50e+00', ... '1.20e+01 4.00e+00'] >>> adas.strlist2array(lines) array([ 2.3, 5.5, 8.5, 12. , 4. ])