如何在PyTable中存储字符串的数组或列表?

2024-06-28 21:56:03 发布

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

例如,我有下面的表描述。在SpectrumL中,我想存储一个(谱图),我还不知道确切的大小。类似地,我想存储一些标记(将是字符串),它们的大小将因记录而异。但是,当我尝试为此执行build语句时,我得到以下错误:

TypeError: Passing an incorrect value to a table column. Expected a Col (or subclass) instance and got: "StringAtom(itemsize=20, shape=(), dflt='')". Please make use of the Col(), or descendant, constructor to properly initialize columns. 

我执行的语句是:

^{pr2}$

表语句类是:

   class BuildTable(IsDescription):
        artist_id = StringCol(100)
        tags = StringAtom(itemsize = 20)
        spectrumL = Float64Atom((5000, 1))
        spectrumR = Float64Atom((5000, 1))
        frequency = Float64Atom((5000, 1))

有人能帮忙看看这个吗?我在理解文档方面有点困难。谢谢!在


Tags: orto字符串标记build错误记录col
1条回答
网友
1楼 · 发布于 2024-06-28 21:56:03

错误消息包含所有信息。您必须使用Col或子类,但您提供的是Atoms。在

table语句必须如下所示:

class BuildTable(IsDescription):
        artist_id = StringCol(100)
        tags = StringCol(itemsize = 20)
        spectrumL = Float64Col(shape=(5000, 1))
        spectrumR = Float64Col(shape=(5000, 1))
        frequency = Float64Col(shape=(5000, 1))

如果要在一个单元格中存储多个值,则必须依赖多维单元格(请参见here)。在

相关问题 更多 >