[英]How to save ragged tensor as a file?
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.
张量由嵌套的数字数组组成,点后有 4 个符号。 (I'm working in a Google Colab and using Google disk to save my files, I know only Python a little bit).
(我在 Google Colab 工作并使用 Google 磁盘保存我的文件,我只知道 Python 一点点)。
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)这是我的数据:我采用“sim_fasttex”这一列,这是一个不同长度列表的列表,根据“h”和“w”重塑它们中的每一个,并将所有这些矩阵收集在一个列表中,所以最后它将是形状参差不齐的张量(初始表中的行数、矩阵的可变长度、矩阵的可变高度)
I don't know your context but,我不知道你的背景,但是,
You can save any object to a file using the pickle
module.您可以使用
pickle
模块将任何 object 保存到文件中。 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:稍后您可以加载相同的 object:
import pickle
with open("a_file_name.pkl", "rb") as f:
the_object = pickle.load(f)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.