【发布时间】:2018-03-07 11:41:21
【问题描述】:
我有一个大小为 (3997,29) 的 numpy 数组(arr)。我正在使用这个数组来创建一个数据集。该数组具有整数和浮点变量。所以 dtype 是参考。但是当我执行它时,我得到以下错误。
"ValueError: Not a location id (Invalid object id)"
with h5py.File("test1.h5", 'w') as f:
grp = f.create_group('Nodes')
with h5py.File("test1.h5", 'r+') as f:
grp = f.require_group('Nodes')
ref_dtype = h5py.special_dtype(ref=h5py.Reference)
arrshape = np.shape(arr)
dset = grp.create_dataset('Init' ,arrshape, dtype = ref_dtype , data= arr)
错误发生在最后一行。以下是回溯消息
dset = f.create_dataset('Init' ,arrshape, dtype = ref_dtype , data= arr)
文件“C:\Users\rupesh.n\AppData\Local\Continuum\anaconda3\lib\site-packages\h5py_hl\group.py”,第 108 行,在 create_dataset dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
文件“C:\Users\rupesh.n\AppData\Local\Continuum\anaconda3\lib\site-packages\h5py_hl\dataset.py”,第 137 行,在 make_new_dset dset_id = h5d.create(parent.id, None, tid, sid, dcpl=dcpl)
文件“h5py_objects.pyx”,第 54 行,在 h5py._objects.with_phil.wrapper 中
文件“h5py_objects.pyx”,第 55 行,在 h5py._objects.with_phil.wrapper 中
文件“h5py\h5d.pyx”,第 79 行,在 h5py.h5d.create 中
ValueError: Not a location id (Invalid object id)
【问题讨论】:
-
我可以猜到错误发生在最后一行,但通常我们要求从错误中回溯来确定。另一个疯狂的猜测是当你尝试访问
grp时f没有打开,而invalid object id指的是grp。除了猜测,我们还需要minimal reproducible example。 -
@Vovanrock2002,是的,错误发生在最后一行。更新了回溯消息。
-
问题已解决。一旦我们退出循环,文件对象就被关闭了。现在解决了。
标签: python numpy object-identity