【问题标题】:Is there any way to read numpy array in Azure Blob Storage in python?有没有办法在 python 中读取 Azure Blob Storage 中的 numpy 数组?
【发布时间】:2020-01-07 11:48:17
【问题描述】:

我想从 Azure 函数中的 python 代码读取存储在 Azure Blob 存储中的 numpy 数组。我做不到。我尝试使用 BlockBlobService 但无法成功。

寻求帮助/建议。

【问题讨论】:

    标签: python azure-functions azure-blob-storage numpy-ndarray


    【解决方案1】:

    简单的解决方案是使用 Azure Storage SDK for Python 将 blob 内容下载到内存,然后使用函数numpy.frombuffer 将 blob 的内存内容加载为一维数组并连续执行任何操作随你喜欢reshape。

    作为参考,有一个 SO 线程 numpy.load from io.BytesIO stream 与您的相同,我用三个示例代码回答了它,用于从 blob 加载 npy 或 npz 格式内容。

    如果你想从 Azure Blob Storage 读取一个 csv/json 文件,你也可以生成一个带有 sas 令牌的 blob url,然后使用函数 pandas.read_csv 或 pandas.read_json 和一个 url 参数为 <blob url with sas token> 来直接将csv或json格式的内容读取为pandas数据框,然后转换为numpy数组。

    【讨论】:

      猜你喜欢
      • 2020-02-17
      • 2021-01-02
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多