h5py数据集不接受nam中的“.”或“/”

2024-09-30 12:24:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个word向量文件,我将其加载到Python中,然后通过将word引用作为数据集键,将向量作为数据来转换为hdf5格式

但是,有些键是“/”和“.”,它们在创建数据集时不起作用,因为h5py假设我指的是路径

我怎样才能避开这个问题

Processing token: ,
Processing token: the
Processing token: .
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-1330b478b6f6> in <module>
     12             tokens[0]=".//
     13         """
---> 14         g = f.create_group(tokens[0])
     15         g.create_dataset("vec",data=np.array(tokens[1:], dtype=np.float))
     16 f.close()

~\AppData\Roaming\Python\Python37\site-packages\h5py\_hl\group.py in create_group(self, name, track_order)
     66             name, lcpl = self._e(name, lcpl=True)
     67             gcpl = Group._gcpl_crt_order if track_order else None
---> 68             gid = h5g.create(self.id, name, lcpl=lcpl, gcpl=gcpl)
     69             return Group(gid)
     70 

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\h5g.pyx in h5py.h5g.create()

ValueError: Unable to create group (name already exists)

当我跳过“.”时:

Processing token: ,
Processing token: the
Processing token: .
Processing token: and
Processing token: to
Processing token: of
Processing token: a
Processing token: in
Processing token: is
Processing token: for
Processing token: that
Processing token: I
Processing token: it
Processing token: on
Processing token: with
Processing token: )
Processing token: :
Processing token: "
Processing token: (
Processing token: The
Processing token: you
Processing token: was
Processing token: are
Processing token: or
Processing token: this
Processing token: as
Processing token: have
Processing token: at
Processing token: from
Processing token: !
Processing token: 's
Processing token: but
Processing token: by
Processing token: not
Processing token: ?
Processing token: your
Processing token: all
Processing token: /
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-cf36d0700543> in <module>
      7         if tokens[0] == ".":
      8             continue
----> 9         g = f.create_group(tokens[0])
     10         g.create_dataset("vec",data=np.array(tokens[1:], dtype=np.float))
     11 f.close()

~\AppData\Roaming\Python\Python37\site-packages\h5py\_hl\group.py in create_group(self, name, track_order)
     66             name, lcpl = self._e(name, lcpl=True)
     67             gcpl = Group._gcpl_crt_order if track_order else None
---> 68             gid = h5g.create(self.id, name, lcpl=lcpl, gcpl=gcpl)
     69             return Group(gid)
     70 

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\h5g.pyx in h5py.h5g.create()

ValueError: Unable to create group (name already exists)

Tags: nameinselftokenobjectscreategrouporder

热门问题