what is the fastest way in python to convert a string with formatted numbers in an numpy array

前端 未结 2 1970
情深已故
情深已故 2021-01-22 08:17

I have a large ASCII file (~100GB) which consists of roughly 1.000.000 lines of known formatted numbers which I try to process with python. The file is too large to read in comp

相关标签:
2条回答
  • 2021-01-22 08:20

    Have you tried numpyp.fromstring?

    np.fromstring(line, dtype=np.float, sep=" ")
    
    0 讨论(0)
  • 2021-01-22 08:27

    The np.genfromtxt function is a speed champion if you can get it to match you input format.

    If not, then you may already be using the fastest method. Your line-by-line split-into-array approach exactly matches the SciPy Cookbook examples.

    0 讨论(0)
提交回复
热议问题