首页 > 解决方案 > FileNotFoundError: [Errno2] | Python, using NumPy save and load

问题描述

So here is my code that saves an array and later loads it so i can sum all the arrays, it works just fine, it creates the folder and the file itself, it saves and then loads the file and completes the task. ( 1st image ). Do you have any other idea how can i get this done without saving to an external file ?

Here is another code in the same project using the same numpy.save technique and it does not run, i tried a lot to find a solution, i used the exact path and had the same error ( 2nd image)

Do you have any idea how can i fix this ? It drives me crazy!

Thank you in advance!

标签: python-3.xnumpyscipysympyerrno

解决方案


关于您关于保存/加载数组的更有效方法的第一个问题,我建议在循环外声明一个列表,并将每次迭代创建的新数组附加到该列表中。您可以稍后在另一个循环中访问此列表中的项目以将它们添加(或您想做的任何其他事情......)。

以下是这种技术的说明性使用:

stack = []
for i in range(N):
    temp = numpy.random.rand(dim, dim)
    stack.append(temp)

我用来numpy为二维数组生成随机值……这与示例无关。关键是定义列表并将在循环中创建的临时stack数组附加到它。temp

由于您的数组似乎是完整的浮点数组,因此您也可以转换stack为 numpy 数组以更快地访问 - 然后它变成一个 (2+1)D 数组。不过,这取决于你。

告诉我我是否打对了位置。谢谢!


推荐阅读