Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> #### an example where Huffman's compression ratio >1 >>> asc = str.join("",[chr(c) for c in range(128)]) >>> asc '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f' >>> compression_ratio("zzz", asc+"a"*1000) 1.1428571428571428 >>> 8/7 1.1428571428571428 >>> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> inter1, bits, inter2, text2 = process("abcdabc") >>> inter1 ['a', 'b', 'c', 'd', [4, 3]] >>> bits '01100001011000100110001101100100100000000010000011' >>> len(bits) 50 >>> bin(ord("a")) '0b1100001' >>> [bin(ord(c)) for c in "abcd"] ['0b1100001', '0b1100010', '0b1100011', '0b1100100'] >>> [bits[8*i:8*(i+1)] for i in range(4)] ['01100001', '01100010', '01100011', '01100100'] >>> bits[32], bits[33:45] , bits[45:] ('1', '000000000100', '00011') >>> inter2 ['a', 'b', 'c', 'd', [4, 3]] >>> text2 'abcdabc' >>> >>> inter1, bits, inter2, text2 = process("xyzxyzwxyzw") SyntaxError: invalid syntax >>> inter1, bits, inter2, text2 = process("xyzxyzwxyzw") >>> inter1 ['x', 'y', 'z', [3, 3], 'w', [4, 4]] >>> inter1, bits, inter2, text2 = process("a"*40) >>> inter1 ['a', [1, 31], [1, 8]] >>> (8+2*18)/7/40 0.15714285714285714 >>> lz_ratio("a"*40) 0.15714285714285714 >>> lz_ratio("a"*400) 0.08642857142857142 >>> 18/7/31 0.08294930875576037 >>> lz_ratio("a"*800) 0.085 >>> lz_ratio("a"*1200) 0.08452380952380953 >>> lz_ratio("a"*1500) 0.08476190476190476 >>> lz_ratio("a"*4000) 0.08321428571428571 >>> lz_ratio("hello") 1.1428571428571428 >>> 8/7 1.1428571428571428 >>> lz_ratio("hello"*2) 0.8285714285714286 #Huffman vs. LZ >>> compare_lz_huffman(rand) #random ascii string of length 1000 Huffman compression ratio: 0.9904285714285714 LZ compression ratio: 1.142 >>> s 'abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiiijjjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmmmnnnnnnnnnnnnnnoooooooooooooooppppppppppppppppqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrsssssssssssssssssssttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzz' >>> compare_lz_huffman(s) Huffman compression ratio: 0.6385836385836385 LZ compression ratio: 0.2629222629222629 >>> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> image2bitmap("./guess.jpg") #creates a new .bitmap file under the same directiry >>> im = Matrix.load("./guess.bitmap") >>> im[0,0] #top-left pixel 31 >>> im.dim() (541, 388) >>> im[500:530,100:130].display() >>> im[500:530,100:130].display(zoom=2) >>> im[500:530,100:130].display(zoom=4) >>> im[480:530,100:130].display(zoom=2) >>> im[480:530,100:150].display(zoom=2) >>> im[480:530,100:190].display(zoom=2) >>> im[450:530,100:190].display(zoom=2) >>> im.display() #Eifel >>> image2bitmap("./pic2 003.jpg") #image taken in class >>> Matrix.load("./pic2 003.bitmap") Matrix too large, specify submatrix #class matrix __repr__ printed this >>> im2 = Matrix.load("./pic2 003.bitmap") >>> im2.display() >>> add(im2,30).display() >>> negate(im2).display() >>> what(im2).display() >>> upside_down(im2).display() >>> upside_down_self(im2).display() >>> im.dim() (541, 388) >>> im2.dim() (384, 512) >>> shift(im2, 50).display() >>> Matrix.load("./pic2 003.bitmap") Matrix too large, specify submatrix >>> im2 = Matrix.load("./pic2 003.bitmap") >>> shift(im2, 50).display() >>> shift(im2, 80, 120).display() >>> append(im,im2, 'h').display() >>> append(im2,im, 'h').display() >>> stretch(im2, 'h', 3).display() >>>