我试图将正常窦房结RR间期数据库的内容保存到一个numpy数组中,但是我一直收到一个错误:
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'但是该文件确实存在于目录中。
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(file)
averageArray = np.fromfile(file,dtype=float)
print(averageArray)当我添加路径名时,如下:
averageArray = np.fromfile('normal-sinus-rhythm-rr-interval-database-1.0.0/nsr001.ecg',dtype=float)
print(averageArray)它起作用了。
非常感谢!
发布于 2021-02-03 10:10:46
您只需要在文件名前面添加根目录,以便完整的文件路径是正确的。为此,您可以使用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(".ecg"):
print(os.path.join(root, file))
averageArray = np.fromfile(os.path.join(root, file), dtype=float)发布于 2021-02-03 02:07:02
FileNotFoundError:Errno 2没有这样的文件或目录:-‘nsr001.ecg’
您编写的目录路径没有正在传递的文件,请检查路径。
https://datascience.stackexchange.com/questions/88849
复制相似问题