python system_error ai_generated true

numpy.core._exceptions._ArrayMemoryError:无法为形状 (45000, 45000)、数据类型 float64 的数组分配 15.3 GiB 内存

numpy.core._exceptions._ArrayMemoryError: Unable to allocate 15.3 GiB for an array with shape (45000, 45000) and data type float64

ID: python/numpy-memory-allocation

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-09-05首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

请求的数组超过可用内存;常由稠密距离矩阵或笛卡尔积引起。

English

Requested array exceeds available RAM; often from dense distance matrices or cross joins.

generic

解决方案

  1. 85% 成功率
    Use float32: np.zeros((n, m), dtype=np.float32)
  2. 90% 成功率
    Chunk with sklearn.metrics.pairwise_distances_chunked or use sparse matrices

无效尝试

常见但无效的做法:

  1. 85% 失败

    Frees only a few GB; array still too large

  2. 70% 失败

    Massive slowdown, may still OOM