Monday, 30 December 2019

How can I read from a file with Python from a specific location to a specific location?

Currently, I'm doing:

    source_noise = np.fromfile('data/noise/' + source + '_16k.dat', sep='\n')
    source_noise_start = np.random.randint(
        0, len(source_noise) - len(audio_array))
    source_noise = source_noise[source_noise_start:
                                source_noise_start + len(audio_array)]

My file looks like:

  -5.3302745e+02
  -5.3985005e+02
  -5.8963920e+02
  -6.5875741e+02
  -5.7371864e+02
  -2.0796765e+02
   2.8152341e+02
   6.5398089e+02
   8.6053581e+02

.. and on and on.

This requires that I read the entire file, when all I want to do is read a part of a file. Is there any way for me to do this with Python that will be FASTER than what I'm doing now?



from How can I read from a file with Python from a specific location to a specific location?

No comments:

Post a Comment