如何将不规则张量保存为文件?

发布于 2025-01-15 18:26:38 字数 538 浏览 3 评论 0原文

如何将参差不齐张量作为文件保存在磁盘上,然后在从磁盘打开它的计算中重复使用它?张量由一个嵌套的数字数组组成,点后有 4 个符号。 (我在 Google Colab 工作并使用 Google 磁盘保存我的文件,我只懂一点 Python)。

这是我的数据: 我采用这一列“sim_fasttex”,它是不同长度的列表的列表,根据“h”和“w”重塑每个列表,并将所有这些矩阵收集在一个列表中,所以最终它将成为形状(初始表中的行数、矩阵的可变长度、矩阵的可变高度)

初始数据最终数组

How can I save a ragged tensor as a file on my disk and then reuse it in calculations opening it from the disk? Tensor consists of a nested array of numbers with 4 signs after the point. (I'm working in a Google Colab and using Google disk to save my files, I know only Python a little bit).

Here is my data:
I take this column "sim_fasttex" which is a list of lists of different length, reshape each of them according to "h" and "w" and collect all these matrices in one list, so finally it's going to be a ragged tensor of the shape (number of rows in initial table, variable length of a matrix, variable heigth of a matrix)

initial data
Final array

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2025-01-22 18:26:38

我不知道您的上下文,但是

您可以使用 pickle 模块将任何对象保存到文件中。像这样

import pickle

the_object = object

with open("a_file_name.pkl", "wb") as f:
    pickle.dump(the_object, f)

稍后你可以加载同一个对象:

import pickle
with open("a_file_name.pkl", "rb") as f:
    the_object = pickle.load(f)

I don't know your context but,

You can save any object to a file using the pickle module. Like this

import pickle

the_object = object

with open("a_file_name.pkl", "wb") as f:
    pickle.dump(the_object, f)

And later you can load that same object:

import pickle
with open("a_file_name.pkl", "rb") as f:
    the_object = pickle.load(f)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文