Filenotfounderror: [errno 2] no such file or directory: 'nsr001.ecg' I am trying to save contents of physiobank Normal Sinus Rhythm RR Interval Database into a numpy array but I keep getting an error:
Traceback (most recent call last):
  File &quot;AverageRRI.py&quot;, line 20, in &lt;module&gt;
    averageArray = np.fromfile(file,dtype=float)
FileNotFoundError: [Errno 2] No such file or directory: 'nsr001.ecg'

but the file does exist in the directory.
import os
import numpy as np

for root, dirs, files in os.walk('normal-sinus-rhythm-rr-interval-database-1.0.0'):
    for file in files:
        if file.endswith(&quot;.ecg&quot;):
            print(file)
            averageArray = np.fromfile(file,dtype=float)
            print(averageArray)

When I add the pathname like:
averageArray = np.fromfile('normal-sinus-rhythm-rr-interval-database-1.0.0/nsr001.ecg',dtype=float)
            print(averageArray)

It works.
Thanks so much!
You just need to add the root directory in front of the filename so that the full filepath is correct. For this you can use os.path.join:
import os
import numpy as np

for root, dirs, files in os.walk('normal-sinus-rhythm-rr-interval-database-1.0.0'):
    for file in files:
        if file.endswith(&quot;.ecg&quot;):
            print(os.path.join(root, file))
            averageArray = np.fromfile(os.path.join(root, file), dtype=float)