【问题标题】:Error when creating dataset with h5py python使用 h5py python 创建数据集时出错
【发布时间】:2021-01-02 22:59:18
【问题描述】:

我正在尝试在 Google Colab code I run 中运行代码

但是在第二行

hf = h5py.File('data_1.h5', 'w')

hf.create_dataset('dataset_1', data=x) 

我收到以下错误:

    116         else:
    117             dtype = numpy.dtype(dtype)
    --> 118         tid = h5t.py_create(dtype, logical=1)    
    119     
    120     # Legacy
    h5py/h5t.pyx in h5py.h5t.py_create()
    h5py/h5t.pyx in h5py.h5t.py_create()
    h5py/h5t.pyx in h5py.h5t.py_create()

    TypeError: Object dtype dtype('O') has no native HDF5 equivalent

为什么会出现?根本原因是什么?关于如何解决它的任何想法?

我在 x 中看到的是

    [[array([[[255., 255., 255.],
            [255., 255., 255.],
            [255., 255., 255.],
            ...,
            [255., 255., 255.],
            [255., 255., 255.],
            [255., 255., 255.]],
    
           [[255., 255., 255.],
            [255., 255., 255.],
            [255., 255., 255.],
            .......

【问题讨论】:

  • 我不认为你的x 是一个正确的数字数组。如果是列表,请查看np.array(x)dtype 是什么?形状?
  • 请阅读ml标签的描述。
  • 问题实际上与neural-network 无关 - 请不要向无关标签发送垃圾邮件(已删除)。
  • 感谢您的来信!我会记住的

标签: python dataset h5py


【解决方案1】:

代码的修复是保持 x 像这样:

hf.create_dataset('dataset_1', (len(x),), dtype=dt)
hf['dataset_1'][...] = x

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2014-01-29
    • 2015-10-29
    • 2016-04-08
    • 1970-01-01
    • 2011-07-21
    相关资源
    最近更新 更多