python - Mac OS X 与 Linux 上的 Numpy 和内存分配

标签 python linux macos numpy ubuntu-16.04

我使用 64 位 Python 使用 numpy 加载大型矩阵。

它在 8GB 内存的 Macbook Pro 上运行良好。

>>> from sklearn.preprocessing import MultiLabelBinarizer
>>> mb = MultiLabelBinarizer()
>>> matrix = mb.fit_transform(questions_topics)
>>> sys.getsizeof(matrix) 
47975472376
>>> matrix.shape
(2999967, 1999)

但它在具有 16GB 内存和 10GB 交换空间的 Ubuntu Google VM 实例上引发了 MemoryError

>>> y = mb.fit_transform(questions_topics)
/home/Liwink/anaconda3/lib/python3.5/site-packages/scipy/sparse/base.py in _process_toarray_args(self, order, out)
1037             return out
1038         else:
-> 1039             return np.zeros(self.shape, dtype=self.dtype, order=order)
1040
1041     def __numpy_ufunc__(self, func, method, pos, inputs, **kwargs):
MemoryError:

在Mac OS上加载matrix时需要50G VIRT。 enter image description here

我有两个问题:

  1. 矩阵(大约 50GB)保存在内存还是磁盘中?
  2. 如何在 VM 上加载此矩阵?

最佳答案

谢谢@juanpa.arrivillaga,我通过 increasing the swap 解决了这个问题.

但它仍然不完美,因为在 Ubuntu 上它会先用完内存,但在 Mac OS 上它“节省”了很多内存。

在 Ubuntu 上: enter image description here

在 Mac 操作系统上: enter image description here

在 Ubuntu 上,它比在 Mac OS 上使用更多的 RES。

如何在 Ubuntu 上节省内存?

关于python - Mac OS X 与 Linux 上的 Numpy 和内存分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45027749/

相关文章:

linux - Linux 功能是否划分了可能的特权操作?

macos - 在pycharm终端windon上的提示上设置路径

macos - 编写 VLC 脚本以捕获视频的第一帧 - 无法让命令行工作

r - 调度 R 脚本 - OSX

python - os.kill 没有引发 OSError,但是我没有看到给定的 pid 正在运行

python - CentOS下安装idle-python2.7

python - 导航栏未显示在 bootstrap django 中

node.js - 带有标志 --legacy-watch 的 Nodemon 不适用于 docker Ubuntu/Linux

linux - Linux下如何查看文件创建时间?

python - 类工厂和抽象基类