You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

大数据量下Numpy随机崩溃(关联_multiarray_umath模块),求助解决方案

大数据量下Numpy随机崩溃(关联_multiarray_umath模块),求助解决方案

各位好,我现在碰到一个非常棘手的Numpy崩溃问题,想请大家帮忙支支招:

问题核心情况

Numpy会毫无预兆地突然崩溃,控制台完全没有提前的错误提示或警告,只有崩溃后才会看到这两个退出码之一:

  • Process finished with exit code -1073741819 (0xC0000005)
  • 或者 Process finished with exit code -1073740791 (0xC0000409)

崩溃的代码位置完全不固定,这次可能在np.where调用时挂掉,下次又跑到np.maximum.accumulate,根本没法锁定某一行代码。小数据量(比如处理行数少于10万)的时候一切正常,但处理大数据时,通常运行到第4分钟左右就会直接崩溃。

我已经尝试过的环境组合

为了解决问题,我换了好几个Python和Numpy版本测试,但都没能解决:

  • Python版本:3.13.2、3.12.9、3.12.5
  • Numpy版本:1.26.4、2.2.2、2.1.1

系统错误报告详情

崩溃后从Windows事件查看器里导出的错误信息如下:

Faulting Application Name: python.exe, Version: 3.12.9150.1013, Timestamp: 0x67a232aa
Faulting Module Name: _multiarray_umath.cp312-win_amd64.pyd, Version: 0.0.0.0, Timestamp: 0x00000000
Exception Code: 0xc0000005
Fault Offset: 0x000000000007c502
Faulting Process ID: 0x7324
Faulting Application Start Time: 0x1DB7ACE52598435
Faulting Application Path: C:\Users\Tony\AppData\Local\Programs\Python\Python312\python.exe
Faulting Module Path: C:\Users\Tony\AppData\Local\Programs\Python\Python313\TradingData\Lib\site-packages\numpy\core\_multiarray_umath.cp312-win_amd64.pyd
Report Identifier: 833671e4-3a45-466e-b46c-693883b70457
Faulting Package Full Name:
Faulting Package App ID:

复现代码

我写了一段大概率能复现问题的代码,运行它处理大数据时,通常循环几次后就会崩溃:

import numpy as np
from numpy.lib.stride_tricks import sliding_window_view

for i in range(0,60):

    w = 60
    x = np.random.rand(9000000)
    window = sliding_window_view(x, window_shape=w)


    def cor_max(row):
        try:
            n = np.where(row >= np.quantile(row, 0.9))[0]
            if len(n) == 0:
                return np.nan
            else:
                r = np.corrcoef(n, range(len(n)))[0][1]
            return r
        except:
            return np.nan


    x1 = np.apply_along_axis(cor_max, axis=1, arr=window)
    x1 = np.append(np.empty(w - 1), x1)


    def cor_min(row):
        try:
            n = np.where(row <= np.quantile(row, 0.1))[0]
            if len(n) == 0:
                return np.nan
            else:
                r = np.corrcoef(n, range(len(n)))[0][1]
            return r
        except:
            return np.nan


    x1 = np.apply_along_axis(cor_min, axis=1, arr=window)
    x1 = np.append(np.empty(w - 1), x1)


    def n_max_change(row):
        try:
            cummax = np.maximum.accumulate(row)
            updates = np.diff(cummax) > 0
            n_updates = np.sum(updates)

            return n_updates / len(row)
        except:
            return np.nan


    x1 = np.apply_along_axis(n_max_change, axis=1, arr=window)
    x1 = np.append(np.empty(w - 1), x1)
    print(i)

我自己折腾了好一阵还是没头绪,有没有朋友遇到过类似的情况?或者能给我一些排查、解决的方向?

备注:内容来源于stack exchange,提问作者Антон Орлов

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:18:08