Make notebooks compatible with both python 2 and python 3

main
Aurélien Geron 2016-02-19 12:22:42 +01:00
parent ec681a3174
commit 793c3a2574
3 changed files with 617 additions and 575 deletions

View File

@ -7,31 +7,32 @@
"# Machine Learning Notebooks\n",
"\n",
"Welcome to the Machine Learning Notebooks.\n",
"**This work is in progress.**\n",
"\n",
"## Tools\n",
"* [NumPy](tools_numpy.ipynb)\n",
"* [Matplotlib](tools_matplotlib.ipynb)"
"* [Matplotlib](tools_matplotlib.ipynb)\n",
"\n",
"**This work is in progress, more notebooks are coming soon...**"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,

View File

@ -20,7 +20,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First we need to import the `matplotlib` library."
"First let's make sure that this notebook works well in both python 2 and 3:"
]
},
{
@ -30,6 +30,26 @@
"collapsed": true
},
"outputs": [],
"source": [
"from __future__ import division\n",
"from __future__ import print_function\n",
"from __future__ import unicode_literals"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First we need to import the `matplotlib` library."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import matplotlib"
]
@ -43,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 3,
"metadata": {
"collapsed": false
},
@ -62,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"collapsed": false
},
@ -85,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"collapsed": false,
"scrolled": true
@ -105,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"collapsed": false
},
@ -125,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {
"collapsed": false
},
@ -148,7 +168,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {
"collapsed": false
},
@ -178,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {
"collapsed": false
},
@ -199,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {
"collapsed": false
},
@ -221,7 +241,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {
"collapsed": false
},
@ -241,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {
"collapsed": false
},
@ -263,7 +283,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {
"collapsed": false
},
@ -283,7 +303,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {
"collapsed": false,
"scrolled": true
@ -308,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {
"collapsed": false,
"scrolled": true
@ -330,7 +350,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {
"collapsed": false,
"scrolled": true
@ -365,7 +385,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {
"collapsed": false
},
@ -389,7 +409,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {
"collapsed": false
},
@ -423,7 +443,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {
"collapsed": false,
"scrolled": true
@ -465,7 +485,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {
"collapsed": false
},
@ -483,7 +503,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {
"collapsed": false,
"scrolled": true
@ -527,7 +547,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {
"collapsed": false
},
@ -559,7 +579,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"metadata": {
"collapsed": false
},
@ -581,7 +601,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 24,
"metadata": {
"collapsed": false,
"scrolled": false
@ -608,7 +628,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 25,
"metadata": {
"collapsed": false
},
@ -636,7 +656,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 26,
"metadata": {
"collapsed": false
},
@ -660,7 +680,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 27,
"metadata": {
"collapsed": false,
"scrolled": true
@ -710,7 +730,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 28,
"metadata": {
"collapsed": false
},
@ -755,7 +775,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 29,
"metadata": {
"collapsed": false
},
@ -781,7 +801,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 30,
"metadata": {
"collapsed": false,
"scrolled": true
@ -811,7 +831,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 31,
"metadata": {
"collapsed": false
},
@ -838,7 +858,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 32,
"metadata": {
"collapsed": false
},
@ -859,7 +879,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 33,
"metadata": {
"collapsed": false
},
@ -880,7 +900,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 34,
"metadata": {
"collapsed": false,
"scrolled": true
@ -909,7 +929,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 35,
"metadata": {
"collapsed": false
},
@ -942,7 +962,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 36,
"metadata": {
"collapsed": false
},
@ -962,7 +982,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 37,
"metadata": {
"collapsed": false,
"scrolled": true
@ -999,7 +1019,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 38,
"metadata": {
"collapsed": false
},
@ -1008,7 +1028,7 @@
"import matplotlib.image as mpimg\n",
"\n",
"img = mpimg.imread('my_square_function.png')\n",
"print img.shape, img.dtype"
"print(img.shape, img.dtype)"
]
},
{
@ -1020,7 +1040,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 39,
"metadata": {
"collapsed": false
},
@ -1039,7 +1059,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 40,
"metadata": {
"collapsed": false
},
@ -1059,14 +1079,14 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"img = np.arange(100*100).reshape(100, 100)\n",
"print img\n",
"print(img)\n",
"plt.imshow(img)\n",
"plt.show()"
]
@ -1080,7 +1100,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 42,
"metadata": {
"collapsed": false,
"scrolled": false
@ -1100,7 +1120,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 43,
"metadata": {
"collapsed": false,
"scrolled": true
@ -1125,7 +1145,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 44,
"metadata": {
"collapsed": false,
"scrolled": false
@ -1146,7 +1166,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 45,
"metadata": {
"collapsed": true
},
@ -1169,7 +1189,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 46,
"metadata": {
"collapsed": false
},
@ -1205,7 +1225,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 47,
"metadata": {
"collapsed": false
},
@ -1227,21 +1247,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,

File diff suppressed because it is too large Load Diff