Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 "", line 20, in <module>
    averageArray = np.fromfile(file,dtype=float)
FileNotFoundError: [Errno 2] No such file or directory: 'nsr001.ecg'

but the file does exist in the directory.

Thanks so much!

What I have tried:

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(".ecg"):
            averageArray = np.fromfile(file,dtype=float)

When I add the pathname like:
averageArray = np.fromfile('normal-sinus-rhythm-rr-interval-database-1.0.0/nsr001.ecg',dtype=float)
It works.
Updated 2-Feb-21 22:39pm
oLiontas 3-Feb-21 2:37am    
Set the absolute path and check again

1 solution

When I add the pathname ... It works.
So you've solved your own question.

If you don't include the path, your code will try to find the file in the current working directory. The file does not exist in the current working directory, so you get an error.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900