Skip to content

Commit 15cb732

Browse files
committed
添加了静态的 HTML 文件
Former-commit-id: 0a23739
1 parent c2aa435 commit 15cb732

File tree

133 files changed

+186652
-3816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+186652
-3816
lines changed

03. numpy/03.04 array types.ipynb

Lines changed: 1202 additions & 1202 deletions
Large diffs are not rendered by default.

09. theano/09.01 introduction and installation.ipynb

Lines changed: 206 additions & 212 deletions
Large diffs are not rendered by default.

09. theano/09.02 theano basics.ipynb

Lines changed: 852 additions & 874 deletions
Large diffs are not rendered by default.

09. theano/09.03 gpu on windows.ipynb

Lines changed: 429 additions & 430 deletions
Large diffs are not rendered by default.

09. theano/09.07 softmax on mnist.ipynb

Lines changed: 538 additions & 491 deletions
Large diffs are not rendered by default.

09. theano/09.08 net.ipynb

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.

09. theano/download_mnist.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import os
2-
import os.path
3-
import urllib
4-
import gzip
5-
import shutil
6-
7-
if not os.path.exists('mnist'):
8-
os.mkdir('mnist')
9-
10-
def download_and_gzip(name):
11-
if not os.path.exists(name + '.gz'):
12-
urllib.urlretrieve('http://yann.lecun.com/exdb/' + name + '.gz', name + '.gz')
13-
if not os.path.exists(name):
14-
with gzip.open(name + '.gz', 'rb') as f_in, open(name, 'wb') as f_out:
15-
shutil.copyfileobj(f_in, f_out)
16-
17-
download_and_gzip('mnist/train-images-idx3-ubyte')
18-
download_and_gzip('mnist/train-labels-idx1-ubyte')
19-
download_and_gzip('mnist/t10k-images-idx3-ubyte')
1+
import os
2+
import os.path
3+
import urllib
4+
import gzip
5+
import shutil
6+
7+
if not os.path.exists('mnist'):
8+
os.mkdir('mnist')
9+
10+
def download_and_gzip(name):
11+
if not os.path.exists(name + '.gz'):
12+
urllib.urlretrieve('http://yann.lecun.com/exdb/' + name + '.gz', name + '.gz')
13+
if not os.path.exists(name):
14+
with gzip.open(name + '.gz', 'rb') as f_in, open(name, 'wb') as f_out:
15+
shutil.copyfileobj(f_in, f_out)
16+
17+
download_and_gzip('mnist/train-images-idx3-ubyte')
18+
download_and_gzip('mnist/train-labels-idx1-ubyte')
19+
download_and_gzip('mnist/t10k-images-idx3-ubyte')
2020
download_and_gzip('mnist/t10k-labels-idx1-ubyte')

09. theano/load.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
import numpy as np
2-
import os
3-
4-
datasets_dir = './'
5-
6-
def one_hot(x,n):
7-
if type(x) == list:
8-
x = np.array(x)
9-
x = x.flatten()
10-
o_h = np.zeros((len(x),n))
11-
o_h[np.arange(len(x)),x] = 1
12-
return o_h
13-
14-
def mnist(ntrain=60000,ntest=10000,onehot=True):
15-
data_dir = os.path.join(datasets_dir,'mnist/')
16-
fd = open(os.path.join(data_dir,'train-images-idx3-ubyte'))
17-
loaded = np.fromfile(file=fd,dtype=np.uint8)
18-
trX = loaded[16:].reshape((60000,28*28)).astype(float)
19-
20-
fd = open(os.path.join(data_dir,'train-labels-idx1-ubyte'))
21-
loaded = np.fromfile(file=fd,dtype=np.uint8)
22-
trY = loaded[8:].reshape((60000))
23-
24-
fd = open(os.path.join(data_dir,'t10k-images-idx3-ubyte'))
25-
loaded = np.fromfile(file=fd,dtype=np.uint8)
26-
teX = loaded[16:].reshape((10000,28*28)).astype(float)
27-
28-
fd = open(os.path.join(data_dir,'t10k-labels-idx1-ubyte'))
29-
loaded = np.fromfile(file=fd,dtype=np.uint8)
30-
teY = loaded[8:].reshape((10000))
31-
32-
trX = trX/255.
33-
teX = teX/255.
34-
35-
trX = trX[:ntrain]
36-
trY = trY[:ntrain]
37-
38-
teX = teX[:ntest]
39-
teY = teY[:ntest]
40-
41-
if onehot:
42-
trY = one_hot(trY, 10)
43-
teY = one_hot(teY, 10)
44-
else:
45-
trY = np.asarray(trY)
46-
teY = np.asarray(teY)
47-
1+
import numpy as np
2+
import os
3+
4+
datasets_dir = './'
5+
6+
def one_hot(x,n):
7+
if type(x) == list:
8+
x = np.array(x)
9+
x = x.flatten()
10+
o_h = np.zeros((len(x),n))
11+
o_h[np.arange(len(x)),x] = 1
12+
return o_h
13+
14+
def mnist(ntrain=60000,ntest=10000,onehot=True):
15+
data_dir = os.path.join(datasets_dir,'mnist/')
16+
fd = open(os.path.join(data_dir,'train-images-idx3-ubyte'))
17+
loaded = np.fromfile(file=fd,dtype=np.uint8)
18+
trX = loaded[16:].reshape((60000,28*28)).astype(float)
19+
20+
fd = open(os.path.join(data_dir,'train-labels-idx1-ubyte'))
21+
loaded = np.fromfile(file=fd,dtype=np.uint8)
22+
trY = loaded[8:].reshape((60000))
23+
24+
fd = open(os.path.join(data_dir,'t10k-images-idx3-ubyte'))
25+
loaded = np.fromfile(file=fd,dtype=np.uint8)
26+
teX = loaded[16:].reshape((10000,28*28)).astype(float)
27+
28+
fd = open(os.path.join(data_dir,'t10k-labels-idx1-ubyte'))
29+
loaded = np.fromfile(file=fd,dtype=np.uint8)
30+
teY = loaded[8:].reshape((10000))
31+
32+
trX = trX/255.
33+
teX = teX/255.
34+
35+
trX = trX[:ntrain]
36+
trY = trY[:ntrain]
37+
38+
teX = teX[:ntest]
39+
teY = teY[:ntest]
40+
41+
if onehot:
42+
trY = one_hot(trY, 10)
43+
teY = one_hot(teY, 10)
44+
else:
45+
trY = np.asarray(trY)
46+
teY = np.asarray(teY)
47+
4848
return trX,teX,trY,teY

11. useful tools/11.01 pprint.ipynb

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# pprint 模块:打印 Python 对象"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"`pprint` 是 pretty printer 的缩写,用来打印 Python 数据结构,与 `print` 相比,它打印出来的结构更加整齐,便于阅读。"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {
21+
"collapsed": true
22+
},
23+
"outputs": [],
24+
"source": [
25+
"import pprint"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"生成一个 Python 对象:"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"metadata": {
39+
"collapsed": true
40+
},
41+
"outputs": [],
42+
"source": [
43+
"data = (\n",
44+
" \"this is a string\", \n",
45+
" [1, 2, 3, 4], \n",
46+
" (\"more tuples\", 1.0, 2.3, 4.5), \n",
47+
" \"this is yet another string\"\n",
48+
" )"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"使用普通的 `print` 函数:"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 3,
61+
"metadata": {
62+
"collapsed": false
63+
},
64+
"outputs": [
65+
{
66+
"name": "stdout",
67+
"output_type": "stream",
68+
"text": [
69+
"('this is a string', [1, 2, 3, 4], ('more tuples', 1.0, 2.3, 4.5), 'this is yet another string')\n"
70+
]
71+
}
72+
],
73+
"source": [
74+
"print data"
75+
]
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"metadata": {},
80+
"source": [
81+
"使用 `pprint` 模块中的 `pprint` 函数:"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": 4,
87+
"metadata": {
88+
"collapsed": false
89+
},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"('this is a string',\n",
96+
" [1, 2, 3, 4],\n",
97+
" ('more tuples', 1.0, 2.3, 4.5),\n",
98+
" 'this is yet another string')\n"
99+
]
100+
}
101+
],
102+
"source": [
103+
"pprint.pprint(data)"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {},
109+
"source": [
110+
"可以看到,这样打印出来的公式更加美观。"
111+
]
112+
}
113+
],
114+
"metadata": {
115+
"kernelspec": {
116+
"display_name": "Python 2",
117+
"language": "python",
118+
"name": "python2"
119+
},
120+
"language_info": {
121+
"codemirror_mode": {
122+
"name": "ipython",
123+
"version": 2
124+
},
125+
"file_extension": ".py",
126+
"mimetype": "text/x-python",
127+
"name": "python",
128+
"nbconvert_exporter": "python",
129+
"pygments_lexer": "ipython2",
130+
"version": "2.7.6"
131+
}
132+
},
133+
"nbformat": 4,
134+
"nbformat_minor": 0
135+
}

0 commit comments

Comments
 (0)