python数组内存错误_转换为数组时Python出现内存错误

我的代码如下所示:from sklearn.datasets import load_svmlight_files

import numpy as np

perm1 =np.random.permutation(25000)

perm2 = np.random.permutation(25000)

X_tr, y_tr, X_te, y_te = load_svmlight_files(("dir/file.feat", "dir/file.feat"))

#randomly shuffle data

X_train = X_tr[perm1,:].toarray()[:,0:2000]

y_train = y_tr[perm1]>5 #turn into binary problem

在这里之前,代码还可以正常工作,但是当我试图将另一个对象转换为数组时,我的程序返回一个内存错误。

代码:X_test = X_te[perm2,:].toarray()[:,0:2000]

错误:---------------------------------------------------------------------------

MemoryError Traceback (most recent call last)

in ()

----> 1 X_test = X_test.toarray()

C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\compressed.pyc in toarray(self, order, out)

788 def toarray(self, order=None, out=None):

789 """See the docstring for `spmatrix.toarray`."""

--> 790 return self.tocoo(copy=False).toarray(order=order, out=out)

791

792 ##############################################################

C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\coo.pyc in toarray(self, order, out)

237 def toarray(self, order=None, out=None):

238 """See the docstring for `spmatrix.toarray`."""

--> 239 B = self._process_toarray_args(order, out)

240 fortran = int(B.flags.f_contiguous)

241 if not fortran and not B.flags.c_contiguous:

C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\base.pyc in _process_toarray_args(self, order, out)

697 return out

698 else:

--> 699 return np.zeros(self.shape, dtype=self.dtype, order=order)

700

701

MemoryError:

我是python新手,我不知道是否需要手动修复内存错误。

我的代码的其他部分返回相同的错误(例如使用knn或ann进行训练)。

我该怎么解决?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值