gpt4 book ai didi

python - 创建 HDF5 数据集时出现 "ValueError: Not a location id (Invalid object id)"

转载 作者:行者123 更新时间:2023-12-05 00:13:05 36 4
gpt4 key购买 nike

我有一个大小为 (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: 不是位置 ID(无效的对象 ID)

最佳答案

当有人尝试使用关闭的句柄创建新数据集时,经常会发生此错误。如果您正在迭代,请确保您没有在循环内关闭文件。我遇到了与 OP 相同的问题。

关于python - 创建 HDF5 数据集时出现 "ValueError: Not a location id (Invalid object id)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49151057/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com