numpy svd中的内存错误 [英] memory error in numpy svd

查看:193
本文介绍了numpy svd中的内存错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行numpy svd

I am performing numpy svd

U, S, V = np.linalg.svd(A) 

A的形状是:

(10000, 10000)

由于尺寸过大,它给了我内存错误:

Due to the large size, it gives me memory error :

U, S, V = np.linalg.svd(A, full_matrices=False) # nargout=3
File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 1319, in svd
    work = zeros((lwork,), t)
    MemoryError

那我该如何为我的矩阵找到svd?

Then how can I find svd for my matrix?

推荐答案

一些小技巧: 关闭计算机上打开的所有其他内容.通过将不再需要的变量设置为无",可以消除程序中所有不必要的占用内存的东西.假设您在较早的计算中使用了一个大dict D,但是不再需要它,则将D设置为None.尝试使用dtype = np.int32或dtype = np.float32初始化numpy数组,以降低内存需求.

Some small tips: Close everything else that is open on your computer. Remove all unnecessary memory hogging things in your program by setting the variables you don't need anymore to None. Say you used a big dict D for some computations earlier but don't need it anymore set D = None. Try initializing your numpy arrays with dtype=np.int32 or dtype=np.float32 to lower memory requirements.

根据需要的SVD,还可以查看python的scikit-learn程序包,它们支持许多分解方法(例如PCA和SVD)以及稀疏矩阵支持.

Depending on what you need the SVD for you can also have a look at the scikit-learn package for python, they have support for many decomposition methods such as PCA and SVD together with sparse matrix support.

这篇关于numpy svd中的内存错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆