轉(zhuǎn)載自:https://blog.csdn.net/xovee/article/details/101077022
[報(bào)錯(cuò)] [Ubuntu] [Python] MemoryError: Unable to allocate array with shape (x, x) and data type float64
錯(cuò)誤信息
MemoryError: Unable to allocate array with shape (430949, 430949) and data type float64
系統(tǒng)環(huán)境
Ubuntu 18.04 LTS
Python 3.6
原因分析
據(jù)傳 [1] 是因?yàn)橛|發(fā)了系統(tǒng)的 overcommit handing 模式。
事情是這樣的笨忌,我打算生成一個(gè)形狀為[430949, 430949]的稀疏矩陣,結(jié)果就報(bào)了上述錯(cuò)誤。大致是因?yàn)檫@個(gè)矩陣似乎要占用的空間太大件余,所以系統(tǒng)就提前禁止創(chuàng)建了梯啤。實(shí)際上是用不了那么多內(nèi)存的(稀疏矩陣)卿吐。
解決辦法
首先檢查系統(tǒng)的內(nèi)存過(guò)載處理模式
sudo passwd root
然后輸入當(dāng)前用戶密碼,再給 root 設(shè)定一個(gè)新密碼沟娱,再切換到 root:
變成了#
現(xiàn)在我們擁有了 root 權(quán)限,輸入下面的命令將內(nèi)存過(guò)載處理模式更改為1:
$ echo 1 > /proc/sys/vm/overcommit_memory
然后不出意外的話腕柜,就可以成功創(chuàng)建該矩陣?yán)玻?br> Reference
Iguananaut. (August 15, 2019). Unable to allocate array with shape and data type. Retrieved from https://stackoverflow.com/questions/57507832/unable-to-allocate-array-with-shape-and-data-type
BigCabbageFy. (March 9, 2018). ubuntu下無(wú)法在根目錄創(chuàng)建文件夾济似;permission denied 權(quán)限不足問(wèn)題解決方法. Retrieved from https://blog.csdn.net/bigcabbagefy/article/details/79500090
————————————————
版權(quán)聲明:本文為CSDN博主「Xovee」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議盏缤,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明碱屁。
原文鏈接:https://blog.csdn.net/xovee/article/details/101077022