python - 尝试使用 h5py 库在 python 中打开 .mat 文件时出现“文件存在”错误
问题描述
我尝试使用以下代码访问 .mat 文件中的部分数据(称为“掩码”):
import h5py
import numpy as np
g = h5py.File('/Path/to/file.mat')
x = g["mask"]
print(np.array(x))
对于另一个 .mat 文件,这似乎工作得很好,但不知何故,对于这个我不断收到以下错误消息:
Traceback (most recent call last):
File "/miniconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 190, in make_fid
fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (file signature not found)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/miniconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 193, in make_fid
fid = h5f.open(name, h5f.ACC_RDONLY, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (file signature not found)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 4, in <module>
g = h5py.File('maskH07.mat')
File "/miniconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 394, in __init__
swmr=swmr)
File "/miniconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 195, in make_fid
fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 105, in h5py.h5f.create
OSError: Unable to create file (unable to open file: name = 'maskH07.mat', errno = 17, error message = 'File exists', flags = 15, o_flags = a02)
非常感谢任何帮助
解决方案
推荐阅读
- python - 如何将数据框转换为空间数据?
- javascript - 两个相同的对象,当一个对象改变一个值时,另一个对象也会改变
- swift - Swiftui 向下滑动以关闭纵向而不是横向的模态作品
- python - 用 numpy 向量化 for 循环
- r - 有没有办法从保存为 RDATATMP 文件的工作区图像中恢复数据帧?
- azure - 在 Azure 数据工厂复制管道中使用管道参数
- java - Java 记录和空对象模式?
- scala - 如何提取列值以与火花数据框中的 rlike 进行比较
- ios - CLLLocationManager 并将位置更新传递到应用程序的不同部分
- tensorflow - TensorFlow:如何提供不适合内存的数据集?