【问题标题】:Cannot stack 2D arrays into 3D array无法将 2D 数组堆叠成 3D 数组
【发布时间】:2019-09-27 14:38:22
【问题描述】:

我正在尝试堆叠一些相同大小的二维数组 我的代码如下所示:

import numpy as np
a = np.random.randn(30_140_100)
b = np.random.randn(30_140_100)
c = np.random.randn(30_140_100)
d = np.random.randn(30_140_100)
e = np.random.randn(30_140_100)
f = np.random.randn(30_140_100)

array = np.vstack((a,b,c)).reshape(3, 5490, 5490)

我正在使用一台旧计算机来执行此操作(32 位)。我听说可以分块处理数组并将结果存储在硬盘中。我不知道这是否是一个解决方案,也不知道 python 代码中的实际实现。

非常感谢!

最好的问候

【问题讨论】:

  • 错误是什么?
  • -------------------------------------------------------------------------- MemoryError Traceback (most recent call last) <ipython-input-2-907f62d89df1> in <module> 7 f = np.random.randn(30_140_100) 8 ----> 9 array = np.vstack((a,b,c)).reshape(3, 5490, 5490) ~/anaconda3/lib/python3.7/site-packages/numpy/core/shape_base.py in vstack(tup) 232 233 """ --> 234 return _nx.concatenate([atleast_2d(_m) for _m in tup], 0) 235 236 def hstack(tup): MemoryError:

标签: python arrays numpy stack


【解决方案1】:

内存错误意味着 python 已用完内存来存储其数据。 32 位机器最多只能支持 4 Gb 的内存,考虑到示例中随机数组的大小,这并不是很多。不幸的是,解决这个问题的唯一方法是增加系统上的内存,这在 32 位计算机上无法超过 4Gb。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多