unpack

Why this function uses a lot of memory?

烂漫一生 提交于 2019-12-05 06:14:45
问题 I'm trying to unpack binary vector of 140 Million bits into list. I'm checking the memory usage of this function, but it looks weird. the memory usage rises to 35GB (GB and not MB). how can I reduce the memory usage? sub bin2list { # This sub translates a binary vector to a list of "1","0" my $vector = shift; my @unpacked = split //, (unpack "B*", $vector ); return @unpacked; } 回答1: Scalars contain a lot of information. $ perl -MDevel::Peek -e'Dump("0")' SV = PV(0x42a8330) at 0x42c57b8 REFCNT

Including an unpacked War in the Assembly

为君一笑 提交于 2019-12-05 06:07:06
I have a project which builds a war (no problem). And, that war needs to be packaged with a few shell scripts. Because that war contains properties files that vary from site-to-site, we can't simply install the war as is, but munge the properties files in it. That's what the shell scripts do. I'd like to package my war in my assembly as a unpacked war. I see <unpacked> in the Assembly Descriptor, but I haven't been able to get that to work. Here's my first bin.xml where I just packed the war as is. This works fine: <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly

Pythonic way to unpack an iterator inside of a list

依然范特西╮ 提交于 2019-12-05 05:27:01
问题 I'm trying to figure out what is the pythonic way to unpack an iterator inside of a list. For example: my_iterator = zip([1, 2, 3, 4], [1, 2, 3, 4]) I have come with the following ways to unpack my iterator inside of a list: 1) my_list = [*my_iterator] 2) my_list = [e for e in my_iterator] 3) my_list = list(my_iterator) No 1) is my favorite way to do it since is less code, but I'm wondering if this is also the pythonic way. Or maybe there is another way to achieve this besides those 3 which

Perl pack/unpack and length of binary string

僤鯓⒐⒋嵵緔 提交于 2019-12-04 15:37:18
Consider this short example: $a = pack("d",255); print length($a)."\n"; # Prints 8 $aa = pack("ddddd", 255,123,0,45,123); print length($aa)."\n"; # Prints 40 @unparray = unpack("d "x5, $aa); print scalar(@unparray)."\n"; # Prints 5 print length($unparray[0])."\n" # Prints 3 printf "%d\n", $unparray[0] ' # Prints 255 # As a one-liner: # perl -e '$a = pack("d",255); print length($a)."\n"; $aa = pack("dd", 255,123,0,45,123); print length($aa)."\n"; @unparray = unpack("d "x5, $aa); print scalar(@unparray)."\n"; print length($unparray[0])."\n"; printf "%d\n", $unparray[0] ' Now, I'd expect a double

Overload * operator in python (or emulate it)

不打扰是莪最后的温柔 提交于 2019-12-04 14:47:14
I want to overload the * operator in python. In C++, you can overload the dereference operator, so that you can create a class with a custom way to respond to *alpha . Part of this question is that I don't know exactly, and I mean EXACTLY, what the * operator (unpacking operator as I call it) does. So how can I overload it, or emulate the overloading of it. Eventually I want to be able to do: *alpha with a custom response and return value. EDIT: I found the solution thanks to Joe Kington's comment. As *alpha unpacks according to __iter__ , so I defined a simple class that can be inherited from

Temporarily unpack dictionary

时光毁灭记忆、已成空白 提交于 2019-12-04 09:22:18
Say, I have a dic like this my_dictionary = {'a':1,'c':5,'b':20,'d':7} Now, I want to do this with my dic: if my_dictionary['a'] == 1 and my_dictionary['d'] == 7: print my_dictionary['c'] This looks ridiculous because I am typing my_dictionary 3 times! So is there any syntax which would allow me to do something like this: within my_dictionary: if a == 1 and d == 7: print c This would actually work if I didn't have anything more (in this case b) in my dic: def f(a,d,c): if a == 1 and d == 7: print c f(**my_dictionary) You can change your function to def f(a,d,c,**args): if a == 1 and d == 7:

Python: reading 12 bit packed binary image

牧云@^-^@ 提交于 2019-12-04 06:52:40
I have a 12 bit packed image from a GigE camera. It is a little-endian file and each 3 bytes hold 2 12-bit pixels. I am trying to read this image using python and I tried something like this: import bitstring import numpy with open('12bitpacked1.bin', 'rb') as f: data = f.read() ii=numpy.zeros(2*len(data)/3) ic = 0 for oo in range(0,len(data)/3): aa = bitstring.Bits(bytes=data[oo:oo+3], length=24) ii[ic],ii[ic+1] = aa.unpack('uint:12,uint:12') ic=ic+2 b = numpy.reshape(ii,(484,644)) In short: I read 3 bytes, convert them to bits and then unpack them as two 12-bit integers. The result is,

PHP Pack/unpack - can it handle variable length strings

元气小坏坏 提交于 2019-12-04 04:34:01
问题 I've been trying to figure out if the PHP implementation of Pack/Unpack can do something that the Perl version is able to do. The example I'd like to be able to do in PHP is: http://perldoc.perl.org/perlpacktut.html#String-Lengths # pack a message: ASCIIZ, ASCIIZ, length/string, byte my $msg = pack( 'Z* Z* C/A* C', $src, $dst, $sm, $prio ); # unpack ( $src, $dst, $sm, $prio ) = unpack( 'Z* Z* C/A* C', $msg ); What this Perl code does is described as: Combining two pack codes with a slash (/)

Pythonic way to unpack an iterator inside of a list

送分小仙女□ 提交于 2019-12-03 20:10:27
I'm trying to figure out what is the pythonic way to unpack an iterator inside of a list. For example: my_iterator = zip([1, 2, 3, 4], [1, 2, 3, 4]) I have come with the following ways to unpack my iterator inside of a list: 1) my_list = [*my_iterator] 2) my_list = [e for e in my_iterator] 3) my_list = list(my_iterator) No 1) is my favorite way to do it since is less code, but I'm wondering if this is also the pythonic way. Or maybe there is another way to achieve this besides those 3 which is the pythonic way? This might be a repeat of Fastest way to convert an iterator to a list , but your

Unpack by bits in PHP

做~自己de王妃 提交于 2019-12-02 04:24:15
I want to unpack a binary string into into an array by a weird sequence of 8-8-8-7 bits. I could easily do something like this, for a normal 8-8-8-8 sequence: $b=unpack('C*',$data); for ($i=0,$count=sizeof($b); $i < $count; $i+=4) { $out[]=array($b[$i+1],$b[$i+2],$b[$i+3],$b[$i+4]); } That would give me a 2D array of bytes, grouped by 4. But as the fourth being 7 bits, I just can't think of anything appropriate. Have you got some ideas? Not sure if I completely understand, but if you have packed data in an unaligned / unpadded format, you will want to use some sort of bitstream. Here's a