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 "AverageRRI.py", 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:

Python
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"):
            print(os.path.exists('normal-sinus-rhythm-rr-interval-database-1.0.0/nsr001.ecg'))
            print(file)
            averageArray = np.fromfile(file,dtype=float)
            print(averageArray)

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

1 solution

Quote:
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