实例化numpy数组时出现内存错误 [英] Memory error In instantiating the numpy array

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

问题描述

我有一个50,000个元素的列表 A ,每个元素都是一个形状数组(102400)

I have a list A of a 50,000 elements and each element is an array of shape (102400)

我尝试实例化数组 B .

     B=numpy.array(A)

但这会引发MemoryError异常.我知道内存和大小非常大吗,但是有没有一种方法可以避免numpy中的ndarrays导致此MemoryError ??

But this throws an exception MemoryError.I know that the memory and size is very huge?But is there a way to avoid this MemoryError with ndarrays in numpy ??

推荐答案

作为一种解决方法,您可以避免使用以下方式复制数组:

As a workaround, you could avoid copying the arrays with something like:

B = np.empty(len(A), dtype=object)
for i, a in enumerate(A):
    B[i] = a

这将允许创建dtype object的ndarray,其元素将是A的原始元素.然后,您可以对其执行 some 数组操作.

This would allow to create a ndarray of dtype object whose elements would be the original elements of A. You could then perform some array operations on it.

但是我不确定您是否可以通过这种方式赢得胜利.

But I am not sure you have something to win in going this way.

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

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