首页 \ 问答 \ python中内存高效的2d可扩展数组?(Memory-efficient 2d growable array in python?)

python中内存高效的2d可扩展数组?(Memory-efficient 2d growable array in python?)

我正在开发一个处理大量数据的应用程序。

....并继续运行我的计算机内存。 :(

Python在变量上有大量的内存开销(根据sys.getsizeof())。 例如,一个带有一个整数的基本元组占用56个字节。 一个空列表,64个字节。 严重的开销。

Numpy数组非常适合减少开销。 但它们并不是为了有效增长而设计的(参见最快的方法来增长一个数字阵列 )。 数组( https://docs.python.org/3/library/array.html )似乎很有希望,但它是1d。 我的数据是2d,一个数组的行数任意,列宽度为3个浮点数(理想情况下为float32),另一个数据的列宽为2个整数(理想情况下为uint32)。 显然,使用~80字节的python结构来存储每行12或8个字节的数据将占用我的内存消耗总量。

在Python中将内存使用率保持为“假”2d的唯一现实方法,即将数组作为arr [row * WIDTH + column]并将行计为len(arr)/ WIDTH?


I'm working on an app that processes a lot of data.

.... and keeps running my computer out of memory. :(

Python has a huge amount of memory overhead on variables (as per sys.getsizeof()). A basic tuple with one integer in it takes up 56 bytes, for example. An empty list, 64 bytes. Serious overhead.

Numpy arrays are great for reducing overhead. But they're not designed to grow efficiently (see Fastest way to grow a numpy numeric array). Array (https://docs.python.org/3/library/array.html) seems promising, but it's 1d. My data is 2d, with an arbitrary number of rows and a column width of 3 floats (ideally float32) for one array, and a column width of two ints (ideally uint32) for the other. Obviously, using ~80 bytes of python structure to store 12 or 8 bytes of data per row is going to total my memory consumption.

Is the only realistic way to keep memory usage down in Python to "fake" 2d, aka by addressing the array as arr[row*WIDTH+column] and counting rows as len(arr)/WIDTH?


原文:https://stackoverflow.com/questions/45250182
更新时间:2023-07-28 16:07

最满意答案

通过执行解析到shell cron-launcher.sh的第二个参数解决了该问题

fac是命令从cron echo "toto" >> /tmp/shell.log

SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log

在shell cron-launcher被解析为$2

因此我必须修改我的代码,如下所示:

#!/bin/bash

#Script use to launch cron tasks

SHELL="/bin/bash"
LOGDIR="/var/log/cronlauncher/"

#echo "$USER" >> /tmp/test.log
COMMAND="$2"
eval $COMMAND

The issue was solved by executing the 2nd argument parsed to the shell cron-launcher.sh

The fac is that the command echo "toto" >> /tmp/shell.log from the cron

SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log

is parsed as $2 in the shell cron-launcher.

Hence I juste had to modify my code as follows:

#!/bin/bash

#Script use to launch cron tasks

SHELL="/bin/bash"
LOGDIR="/var/log/cronlauncher/"

#echo "$USER" >> /tmp/test.log
COMMAND="$2"
eval $COMMAND

相关问答

更多
  • 看看django的自定义管理命令 。 作为一个基本的例子: from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User from perfil.models import * class Command(BaseCommand): help = 'What does this do? ' def handle(self, *ar ...
  • 通过执行解析到shell cron-launcher.sh的第二个参数解决了该问题 fac是命令从cron echo "toto" >> /tmp/shell.log SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log 在shell cron-launcher被解析为$2 。 因此我必须修改我的代码,如下所示: #!/bin/bash #Script use to launch cron tasks SHELL ...
  • 没有任何选项的命令crontab从stdin安装crontab。 如果需要附加到旧的crontab, crontab -l将返回当前的crontab。 The command crontab without any options installs a crontab from stdin. crontab -l returns the current crontab if you need to append to the old crontab.
  • 如评论中所述,出现以下错误: E486:找不到图案:2 * * * * 是因为你没有正确编辑而造成的。 也就是说,你正确地说crontab -e然后你进入vi 。 您可以直接键入*/2 * * * * /home/test/test/test.sh ,而不是进入插入模式, vi会尝试将其作为命令执行,而不是。 所以你要做的就是按i进入写入模式。 然后,就在那时,写下*/2 * * * * /home/test/test/test.sh 。 最后,通过说:wq保存文件。 如果您的cronjob中出现其他问题, ...
  • Cron(至少在Debian中)不会执行超过1个硬链接的crontabs,请参阅错误647193 。 由于Docker使用覆盖,所以导致多个链接指向文件,因此您必须在启动脚本中touch它,以便链接被切断: touch /etc/crontab /etc/cron.*/* Cron (at least in Debian) does not execute crontabs with more than 1 hardlink, see bug 647193. As Docker uses overlays ...
  • 在这种情况下,您无需激活virtualenv。 你可以在virtualenv的bin目录中使用python。 */10 * * * * source /home/username/Envs/project_name/bin/python /home/username/Code/project_name/manage.py post_message > /dev/null You don't need to activate the virtualenv in this case. You can just ...
  • 我读了你的评论,你绝对应该在尝试安排它之前让它手动运行。 从php配置获取信息: 要找出which php安装路径,对于版本php -v 最后确保脚本是可执行的chmod +x /home/eem/cars1/cron/cronjob1.php I finally managed to find out what is wrong with the code. It turned out the ADOdb libraries are not suppor ...
  • 使用这里的帮助,无论出于何种原因,即使我有正确的代码使脚本可执行,这条线似乎没有在我的部署脚本中触发,这意味着我所要做的就是之后运行它来制作它可执行,然后一切正常。 获得的经验:如果您需要这样做,上面的代码可以正常工作 Using the help from here, for whatever reason, even though I had the code correct to make the script executable, this line didn't seem to fire in ...
  • 也许在/etc/cron.d/my_cron_job ? 我假设Chef使用作业名称来创建一个单独的文件,因为它更容易管理它而不是crontab,其他可能是非厨师工作。 Maybe in /etc/cron.d/my_cron_job? I assume Chef uses the job name to create a separate file because it's easier to manage it instead of a crontab where other maybe non-che ...
  • 在你的问题中,你正在运行的cron就像 2 * * * * . $HOME/.bash_profile ~/jek.sh 您需要使用此条目更正/验证多项内容 检查两者的文件权限是777还是775 ( rwx )。 如果没有,则使用chmod 777 ~/jek.sh更改文件权限 检查他们每个人在他们的shebang行中定义他们是哪个语言脚本( #!/usr/local/env sh ) 用&&或;分隔两个脚本 这样它们都能正常运行。 目前,第二个脚本的名称将被视为第一个脚本的参数。 有一个. 在2 * * ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。