Skip to content

Commit 7003e5d

Browse files
committed
much hacking
1 parent 25c533e commit 7003e5d

23 files changed

+5622
-3584
lines changed

1 lists.ipynb

+259-259
Large diffs are not rendered by default.

1 performance.ipynb

+152-152
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,153 @@
1-
{
2-
"metadata": {
3-
"name": "",
4-
"signature": "sha256:1eaf7250058f025adf584533cdd58bad6bfcf880b7e6c17aa07fa00eda61f5ef"
5-
},
6-
"nbformat": 3,
7-
"nbformat_minor": 0,
8-
"worksheets": [
9-
{
10-
"cells": [
11-
{
12-
"cell_type": "code",
13-
"collapsed": false,
14-
"input": [
15-
"from random import random\n",
16-
"\n",
17-
"def random2d(n=1000):\n",
18-
" return [[random() for j in range(n)] for i in range(n)]\n",
19-
"\n",
20-
"# now let's do 2d averaging\n",
21-
"def average2d(a):\n",
22-
" # there's no way to tell how many elements\n",
23-
" # there are because each list in the list of lists\n",
24-
" # could be a different length\n",
25-
" n, s = 0, 0\n",
26-
" for row in a:\n",
27-
" for element in row:\n",
28-
" s += element\n",
29-
" n += 1\n",
30-
" return s / n\n",
31-
"\n",
32-
"n = 3000\n",
33-
"\n",
34-
"R = random2d(n)\n",
35-
"average2d(R)"
36-
],
37-
"language": "python",
38-
"metadata": {},
39-
"outputs": [
40-
{
41-
"metadata": {},
42-
"output_type": "pyout",
43-
"prompt_number": 2,
44-
"text": [
45-
"0.5001795139728076"
46-
]
47-
}
48-
],
49-
"prompt_number": 2
50-
},
51-
{
52-
"cell_type": "code",
53-
"collapsed": false,
54-
"input": [
55-
"%%timeit\n",
56-
"\n",
57-
"# how fast is this?\n",
58-
"average2d(R)"
59-
],
60-
"language": "python",
61-
"metadata": {},
62-
"outputs": [
63-
{
64-
"output_type": "stream",
65-
"stream": "stdout",
66-
"text": [
67-
"1 loops, best of 3: 604 ms per loop\n"
68-
]
69-
}
70-
],
71-
"prompt_number": 3
72-
},
73-
{
74-
"cell_type": "code",
75-
"collapsed": false,
76-
"input": [
77-
"import numpy as np\n",
78-
"\n",
79-
"R = np.random.uniform(size=(n,n))\n",
80-
"R"
81-
],
82-
"language": "python",
83-
"metadata": {},
84-
"outputs": [
85-
{
86-
"metadata": {},
87-
"output_type": "pyout",
88-
"prompt_number": 10,
89-
"text": [
90-
"array([[ 0.16442591, 0.06019215, 0.13574315, ..., 0.95115628,\n",
91-
" 0.32276626, 0.69702153],\n",
92-
" [ 0.31768723, 0.93409853, 0.34722531, ..., 0.52851659,\n",
93-
" 0.36773928, 0.9316535 ],\n",
94-
" [ 0.91488032, 0.88127737, 0.87042717, ..., 0.85553466,\n",
95-
" 0.30377961, 0.95292511],\n",
96-
" ..., \n",
97-
" [ 0.86619297, 0.64068635, 0.0671692 , ..., 0.52829387,\n",
98-
" 0.52078797, 0.13971299],\n",
99-
" [ 0.50046661, 0.2426449 , 0.59872748, ..., 0.76729318,\n",
100-
" 0.5692301 , 0.74018849],\n",
101-
" [ 0.87473508, 0.64598814, 0.91931996, ..., 0.71743977,\n",
102-
" 0.27391853, 0.18721739]])"
103-
]
104-
}
105-
],
106-
"prompt_number": 10
107-
},
108-
{
109-
"cell_type": "code",
110-
"collapsed": false,
111-
"input": [
112-
"np.mean(R)"
113-
],
114-
"language": "python",
115-
"metadata": {},
116-
"outputs": [
117-
{
118-
"metadata": {},
119-
"output_type": "pyout",
120-
"prompt_number": 11,
121-
"text": [
122-
"0.50023059066229336"
123-
]
124-
}
125-
],
126-
"prompt_number": 11
127-
},
128-
{
129-
"cell_type": "code",
130-
"collapsed": false,
131-
"input": [
132-
"%%timeit\n",
133-
"\n",
134-
"np.mean(R)"
135-
],
136-
"language": "python",
137-
"metadata": {},
138-
"outputs": [
139-
{
140-
"output_type": "stream",
141-
"stream": "stdout",
142-
"text": [
143-
"100 loops, best of 3: 10.4 ms per loop\n"
144-
]
145-
}
146-
],
147-
"prompt_number": 12
148-
}
149-
],
150-
"metadata": {}
151-
}
152-
]
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:1eaf7250058f025adf584533cdd58bad6bfcf880b7e6c17aa07fa00eda61f5ef"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "code",
13+
"collapsed": false,
14+
"input": [
15+
"from random import random\n",
16+
"\n",
17+
"def random2d(n=1000):\n",
18+
" return [[random() for j in range(n)] for i in range(n)]\n",
19+
"\n",
20+
"# now let's do 2d averaging\n",
21+
"def average2d(a):\n",
22+
" # there's no way to tell how many elements\n",
23+
" # there are because each list in the list of lists\n",
24+
" # could be a different length\n",
25+
" n, s = 0, 0\n",
26+
" for row in a:\n",
27+
" for element in row:\n",
28+
" s += element\n",
29+
" n += 1\n",
30+
" return s / n\n",
31+
"\n",
32+
"n = 3000\n",
33+
"\n",
34+
"R = random2d(n)\n",
35+
"average2d(R)"
36+
],
37+
"language": "python",
38+
"metadata": {},
39+
"outputs": [
40+
{
41+
"metadata": {},
42+
"output_type": "pyout",
43+
"prompt_number": 2,
44+
"text": [
45+
"0.5001795139728076"
46+
]
47+
}
48+
],
49+
"prompt_number": 2
50+
},
51+
{
52+
"cell_type": "code",
53+
"collapsed": false,
54+
"input": [
55+
"%%timeit\n",
56+
"\n",
57+
"# how fast is this?\n",
58+
"average2d(R)"
59+
],
60+
"language": "python",
61+
"metadata": {},
62+
"outputs": [
63+
{
64+
"output_type": "stream",
65+
"stream": "stdout",
66+
"text": [
67+
"1 loops, best of 3: 604 ms per loop\n"
68+
]
69+
}
70+
],
71+
"prompt_number": 3
72+
},
73+
{
74+
"cell_type": "code",
75+
"collapsed": false,
76+
"input": [
77+
"import numpy as np\n",
78+
"\n",
79+
"R = np.random.uniform(size=(n,n))\n",
80+
"R"
81+
],
82+
"language": "python",
83+
"metadata": {},
84+
"outputs": [
85+
{
86+
"metadata": {},
87+
"output_type": "pyout",
88+
"prompt_number": 10,
89+
"text": [
90+
"array([[ 0.16442591, 0.06019215, 0.13574315, ..., 0.95115628,\n",
91+
" 0.32276626, 0.69702153],\n",
92+
" [ 0.31768723, 0.93409853, 0.34722531, ..., 0.52851659,\n",
93+
" 0.36773928, 0.9316535 ],\n",
94+
" [ 0.91488032, 0.88127737, 0.87042717, ..., 0.85553466,\n",
95+
" 0.30377961, 0.95292511],\n",
96+
" ..., \n",
97+
" [ 0.86619297, 0.64068635, 0.0671692 , ..., 0.52829387,\n",
98+
" 0.52078797, 0.13971299],\n",
99+
" [ 0.50046661, 0.2426449 , 0.59872748, ..., 0.76729318,\n",
100+
" 0.5692301 , 0.74018849],\n",
101+
" [ 0.87473508, 0.64598814, 0.91931996, ..., 0.71743977,\n",
102+
" 0.27391853, 0.18721739]])"
103+
]
104+
}
105+
],
106+
"prompt_number": 10
107+
},
108+
{
109+
"cell_type": "code",
110+
"collapsed": false,
111+
"input": [
112+
"np.mean(R)"
113+
],
114+
"language": "python",
115+
"metadata": {},
116+
"outputs": [
117+
{
118+
"metadata": {},
119+
"output_type": "pyout",
120+
"prompt_number": 11,
121+
"text": [
122+
"0.50023059066229336"
123+
]
124+
}
125+
],
126+
"prompt_number": 11
127+
},
128+
{
129+
"cell_type": "code",
130+
"collapsed": false,
131+
"input": [
132+
"%%timeit\n",
133+
"\n",
134+
"np.mean(R)"
135+
],
136+
"language": "python",
137+
"metadata": {},
138+
"outputs": [
139+
{
140+
"output_type": "stream",
141+
"stream": "stdout",
142+
"text": [
143+
"100 loops, best of 3: 10.4 ms per loop\n"
144+
]
145+
}
146+
],
147+
"prompt_number": 12
148+
}
149+
],
150+
"metadata": {}
151+
}
152+
]
153153
}

0 commit comments

Comments
 (0)