我想将大型浮点向量存储为 dynamodb 表中的列之一。我知道这里以前的答案使用 numpy 数组 .toString() 来存储它,然后用 np.frombuffer(x,dtype=float) 进行解码。但是我无法使用此方法,因为我只需要使用 python 标准库。
我目前正在使用 ','.join(map(str, q))
其中 q 是用于编码矢量的 float 列表。然后为了解码它,我将分割字符串。我想知道是否有更有效的方法使用标准库对列表进行编码以优化解码时间。
最佳答案
使用 Pickle 序列化您的矢量对象或numpy.save
并存储binary在 DynamoDB 中。
当您从 Dynamo 检索时,请使用 Pickle 或 numpy.load
再次转换为向量。
Beware that DynamoDB has a limit of 400kb for each item. You mentioned 'large vectors', make sure you can stay within this limit. If not, consider another database or maybe store on AWS S3.
关于python - 在 dynamoDB 表中存储大型列表以优化解码时间的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57102348/