python - 在 dynamoDB 表中存储大型列表以优化解码时间的最佳方法

标签 python list amazon-web-services amazon-dynamodb

我想将大型浮点向量存储为 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/

相关文章:

python - 如何处理 Django 迁移中的异常?

c# - 将托管 C# 列表返回到非托管 C++ 代码

python - 为随机选择的变量分配一个值

python - 是否有一种快速算法可以将集合的所有分区生成为大小为 2 的子集(以及一个大小为 1 的子集)?

amazon-web-services - 尝试通过 CloudFormation 创建 SG 和 RDS 时显示 `Invalid security group`

python - API Gateway 中的 AWS Lambda 集成响应 - {"message": "Internal server error"}

python - 如何将 _sre.SRE_Match 类型转换为字符串和整数

python - 如何在 python 中返回最重复的字母?

python - numpy loadtxt 和 savetxt 多个文件?

amazon-web-services - 在 S3 AWS 存储桶上启用 MFA 删除