python – 免费Numpy内存到位

python – 免费Numpy内存到位,第1张

概述有没有办法让numpy释放数组使用的内存?我不能只运行del数组,因为数组在别处被引用. 为什么这很重要以及为什么我认为这是安全的示例: def run(): arr = np.array(....) arr2 = process(arr) fit(arr2) 我能够编辑进程但不能运行.现在arr持有大量内存,在进程运行后不​​再需要.我想在创建arr2后从进程内删除arr中的内 有没有办法让numpy释放数组使用的内存?我不能只运行del数组,因为数组在别处被引用.

为什么这很重要以及为什么我认为这是安全的示例:

def run():   arr = np.array(....)   arr2 = process(arr)   fit(arr2)@H_404_14@  

我能够编辑进程但不能运行.现在arr持有大量内存,在进程运行后不​​再需要.我想在创建arr2后从进程内删除arr中的内容.

解决方法 您可以尝试将数组的大小调整为一个小数组:

arr.resize((2,),refcheck=False)@H_404_14@  

它就地更改了数组:

a.resize(new_shape,refcheck=True)

Change shape and size of array in-place.

Notes

This reallocates space for the data area if necessary.

Only contiguous arrays (data elements consecutive in memory) can be
resized.

The purpose of the reference count check is to make sure you
do not use this array as a buffer for another Python object and then
reallocate the memory. However,reference counts can increase in
other ways so if you are sure that you have not shared the memory
for this array with another Python object,then you may safely set
refcheck to False.

总结

以上是内存溢出为你收集整理的python – 免费Numpy内存到位全部内容,希望文章能够帮你解决python – 免费Numpy内存到位所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1197567.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存