我的代码如下所示:
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
Run Code Online (Sandbox Code Playgroud)
代码工作正常,直到这里,但当我尝试将另一个对象转换为数组时,我的程序返回内存错误.
码:
X_test = X_te[perm2,:].toarray()[:,0:2000]
Run Code Online (Sandbox Code Playgroud)
错误:
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
<ipython-input-7-31f5e4f6b00c> in <module>()
----> 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 …Run Code Online (Sandbox Code Playgroud) 所以我有以下C代码:
for (int i = 0; i < nWallSegments; i+=4) {
fscanf(fin, "%le %le %le %le", &wallSegments[i+0], &wallSegments[i+1], &wallSegments[i+2], &wallSegments[i+3]);
}
for (int i = 0; i < nWallSegments; i+=4) {
nWallPoints += ceil(dist(wallSegments[i+0], wallSegments[i+1], wallSegments[i+2], wallSegments[i+3]) / dWallPoints) - 2;
// other stuff here
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我收到以下错误.来自Python背景,我不知道发生了什么.我在网上搜索了答案,但没有运气.
Prog.c:44:12: error: redefinition of 'i'
for (int i = 0; i < nWallSegments; i+=4) {
^
Prog.c:40:12: note: previous definition is here
for (int i = 0; i < nWallSegments; i+=4) {c
Run Code Online (Sandbox Code Playgroud)