python - How to use scipy weave and sscanf to parse string to numpy array? -
i'm working on scientific python code speed up. 1 specific problem reading in lots data stored in text files using formated strings. figured out approach using split() , np.array() works nicely, slow if compared i'm used fortran.
i'm wondering weather scipy.weave used here, unfortunately i'm no expert in c. here example:
line =" 0.7711408e-01 0.7616138e-01 0.7521919e-01" arr = np.array(line.split(),dtype=np.float) print arr
this works, far slow large data sets. this, bu working?
line =" 0.7711408e-01 0.7616138e-01 0.7521919e-01" arr = np.zeros(3) weave.inline("""sscanf(std::string(line).c_str(),"%f %f %f",arr);""",['line','arr']) print arr
Comments
Post a Comment