Skip to content

Instantly share code, notes, and snippets.

@elistevens
Last active June 25, 2016 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elistevens/03e22f4684fb77d3edfe13ffcd406ef4 to your computer and use it in GitHub Desktop.
Save elistevens/03e22f4684fb77d3edfe13ffcd406ef4 to your computer and use it in GitHub Desktop.
>>> import numpy as np
>>> import cPickle as p
>>> with open('cp123.pkl', 'w') as f: p.dump(np.array([1,2,3], dtype=np.int8), f)
...
>>>
>>>> with open('pp123.pkl', 'w') as f: p.dump(np.array([1,2,3], dtype=np.int8), f)
elis@xps:~/edit/play/droidblue$ hexdump -C cp123.pkl
00000000 63 6e 75 6d 70 79 2e 63 6f 72 65 2e 6d 75 6c 74 |cnumpy.core.mult|
00000010 69 61 72 72 61 79 0a 5f 72 65 63 6f 6e 73 74 72 |iarray._reconstr|
00000020 75 63 74 0a 70 31 0a 28 63 6e 75 6d 70 79 0a 6e |uct.p1.(cnumpy.n|
00000030 64 61 72 72 61 79 0a 70 32 0a 28 49 30 0a 74 53 |darray.p2.(I0.tS|
00000040 27 62 27 0a 74 52 70 33 0a 28 49 31 0a 28 49 33 |'b'.tRp3.(I1.(I3|
00000050 0a 74 63 6e 75 6d 70 79 0a 64 74 79 70 65 0a 70 |.tcnumpy.dtype.p|
00000060 34 0a 28 53 27 69 31 27 0a 49 30 0a 49 31 0a 74 |4.(S'i1'.I0.I1.t|
00000070 52 70 35 0a 28 49 33 0a 53 27 7c 27 0a 4e 4e 4e |Rp5.(I3.S'|'.NNN|
00000080 49 2d 31 0a 49 2d 31 0a 49 30 0a 74 62 49 30 30 |I-1.I-1.I0.tbI00|
00000090 0a 53 27 5c 78 30 31 5c 78 30 32 5c 78 30 33 27 |.S'\x01\x02\x03'|
000000a0 0a 74 62 2e |.tb.|
000000a4
elis@xps:~/edit/play/droidblue$ hexdump -C pp123.pkl
00000000 63 5f 6e 75 6d 70 79 70 79 2e 6d 75 6c 74 69 61 |c_numpypy.multia|
00000010 72 72 61 79 0a 5f 72 65 63 6f 6e 73 74 72 75 63 |rray._reconstruc|
00000020 74 0a 70 31 0a 28 63 6e 75 6d 70 79 0a 6e 64 61 |t.p1.(cnumpy.nda|
00000030 72 72 61 79 0a 70 32 0a 28 49 30 0a 74 70 33 0a |rray.p2.(I0.tp3.|
00000040 53 27 62 27 0a 70 34 0a 74 70 35 0a 52 70 36 0a |S'b'.p4.tp5.Rp6.|
00000050 28 49 31 0a 28 49 33 0a 74 70 37 0a 63 6e 75 6d |(I1.(I3.tp7.cnum|
00000060 70 79 0a 64 74 79 70 65 0a 70 38 0a 28 53 27 69 |py.dtype.p8.(S'i|
00000070 31 27 0a 70 39 0a 49 30 0a 49 31 0a 74 70 31 30 |1'.p9.I0.I1.tp10|
00000080 0a 52 70 31 31 0a 28 49 33 0a 53 27 7c 27 0a 70 |.Rp11.(I3.S'|'.p|
00000090 31 32 0a 4e 4e 4e 49 2d 31 0a 49 2d 31 0a 49 30 |12.NNNI-1.I-1.I0|
000000a0 0a 74 70 31 33 0a 62 49 30 30 0a 53 27 5c 78 30 |.tp13.bI00.S'\x0|
000000b0 31 5c 78 30 32 5c 78 30 33 27 0a 70 31 34 0a 74 |1\x02\x03'.p14.t|
000000c0 70 31 35 0a 62 2e |p15.b.|
000000c6
>>> pt.dis(pt.optimize(open('pp123.pkl').read()))
0: c GLOBAL '_numpypy.multiarray _reconstruct'
34: ( MARK
35: c GLOBAL 'numpy ndarray'
50: ( MARK
51: I INT 0
54: t TUPLE (MARK at 50)
55: S STRING 'b'
60: t TUPLE (MARK at 34)
61: R REDUCE
62: ( MARK
63: I INT 1
66: ( MARK
67: I INT 3
70: t TUPLE (MARK at 66)
71: c GLOBAL 'numpy dtype'
84: ( MARK
85: S STRING 'i1'
91: I INT 0
94: I INT 1
97: t TUPLE (MARK at 84)
98: R REDUCE
99: ( MARK
100: I INT 3
103: S STRING '|'
108: N NONE
109: N NONE
110: N NONE
111: I INT -1
115: I INT -1
119: I INT 0
122: t TUPLE (MARK at 99)
123: b BUILD
124: I INT False
128: S STRING '\x01\x02\x03'
144: t TUPLE (MARK at 62)
145: b BUILD
146: . STOP
>>> pt.dis(pt.optimize(open('cp123.pkl').read()))
0: c GLOBAL 'numpy.core.multiarray _reconstruct'
36: ( MARK
37: c GLOBAL 'numpy ndarray'
52: ( MARK
53: I INT 0
56: t TUPLE (MARK at 52)
57: S STRING 'b'
62: t TUPLE (MARK at 36)
63: R REDUCE
64: ( MARK
65: I INT 1
68: ( MARK
69: I INT 3
72: t TUPLE (MARK at 68)
73: c GLOBAL 'numpy dtype'
86: ( MARK
87: S STRING 'i1'
93: I INT 0
96: I INT 1
99: t TUPLE (MARK at 86)
100: R REDUCE
101: ( MARK
102: I INT 3
105: S STRING '|'
110: N NONE
111: N NONE
112: N NONE
113: I INT -1
117: I INT -1
121: I INT 0
124: t TUPLE (MARK at 101)
125: b BUILD
126: I INT False
130: S STRING '\x01\x02\x03'
146: t TUPLE (MARK at 64)
147: b BUILD
148: . STOP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment