Python 3.x Python:MemoryError

Python 3.x Python:MemoryError,python-3.x,Python 3.x,在Python3.5中运行代码时出现了一个错误:MemoryError unq, unq_idx = np.unique(targets, return_inverse=True) unq_cnt = np.bincount(unq_idx) cnt = np.max(unq_cnt) n_targets = np.empty((cnt*len(unq),) + targets.shape[1:], targets.dtype) n_input_patches = np.empty((cnt*l

在Python3.5中运行代码时出现了一个错误:MemoryError

unq, unq_idx = np.unique(targets, return_inverse=True)
unq_cnt = np.bincount(unq_idx)
cnt = np.max(unq_cnt)
n_targets = np.empty((cnt*len(unq),) + targets.shape[1:], targets.dtype)
n_input_patches = np.empty((cnt*len(unq),) + input_patches.shape[1:], input_patches.dtype)
for j in range(len(unq)):
    indices = np.random.choice(np.where(unq_idx==j)[0], cnt)
    n_targets[j*cnt:(j+1)*cnt] = targets[indices]
    n_input_patches[j*cnt:(j+1)*cnt] = input_patches[indices]
错误是:

 n_input_patches = np.empty((cnt*len(unq),) + input_patches.shape[1:], input_patches.dtype)
MemoryError

我不知道密码怎么了。请帮帮我。非常感谢。

基本上,当内存不足时会引发此异常:

本质上,您的代码是为许多对象创建的,因此我会检查您的循环等,或者发布实际输入以获得更清晰的信息