Remove from __future__ imports as we move away from Python 2

main
Aurélien Geron 2019-10-12 16:40:05 +09:30
parent 936e2cf50f
commit f6dfa0ff76
5 changed files with 211 additions and 684 deletions

View File

@ -20,7 +20,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from __future__ import print_function, division, unicode_literals\n",
"import numpy as np\n", "import numpy as np\n",
"\n", "\n",
"%matplotlib nbagg\n", "%matplotlib nbagg\n",

View File

@ -11,22 +11,6 @@
"*Machine Learning relies heavily on Linear Algebra, so it is essential to understand what vectors and matrices are, what operations you can perform with them, and how they can be useful.*" "*Machine Learning relies heavily on Linear Algebra, so it is essential to understand what vectors and matrices are, what operations you can perform with them, and how they can be useful.*"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we start, let's ensure that this notebook works well in both Python 2 and 3:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division, print_function, unicode_literals"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},

View File

@ -26,24 +26,6 @@
"# Plotting your first graph" "# Plotting your first graph"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First let's make sure that this notebook works well in both python 2 and 3:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from __future__ import division, print_function, unicode_literals"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -53,10 +35,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import matplotlib" "import matplotlib"
@ -71,10 +51,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%matplotlib inline\n", "%matplotlib inline\n",
@ -91,9 +69,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
@ -115,7 +91,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -134,9 +109,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 6,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot([-3, -2, 5, 0], [1, 6, 4, 3])\n", "plt.plot([-3, -2, 5, 0], [1, 6, 4, 3])\n",
@ -154,9 +127,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 7,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
@ -177,9 +148,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 8,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot(x, y)\n", "plt.plot(x, y)\n",
@ -207,9 +176,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 9,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot([0, 100, 100, 0, 0, 100, 50, 0, 100], [0, 0, 100, 100, 0, 100, 130, 100, 0])\n", "plt.plot([0, 100, 100, 0, 0, 100, 50, 0, 100], [0, 0, 100, 100, 0, 100, 130, 100, 0])\n",
@ -228,9 +195,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 10,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot([0, 100, 100, 0, 0, 100, 50, 0, 100], [0, 0, 100, 100, 0, 100, 130, 100, 0], \"g--\")\n", "plt.plot([0, 100, 100, 0, 0, 100, 50, 0, 100], [0, 0, 100, 100, 0, 100, 130, 100, 0], \"g--\")\n",
@ -250,9 +215,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 11,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot([0, 100, 100, 0, 0], [0, 0, 100, 100, 0], \"r-\", [0, 100, 50, 0, 100], [0, 100, 130, 100, 0], \"g--\")\n", "plt.plot([0, 100, 100, 0, 0], [0, 0, 100, 100, 0], \"r-\", [0, 100, 50, 0, 100], [0, 100, 130, 100, 0], \"g--\")\n",
@ -270,9 +233,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 12,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot([0, 100, 100, 0, 0], [0, 0, 100, 100, 0], \"r-\")\n", "plt.plot([0, 100, 100, 0, 0], [0, 0, 100, 100, 0], \"r-\")\n",
@ -292,9 +253,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 13,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = np.linspace(-1.4, 1.4, 30)\n", "x = np.linspace(-1.4, 1.4, 30)\n",
@ -313,7 +272,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 14,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -338,7 +296,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 15,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -360,7 +317,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 16,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -394,9 +350,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 17,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.subplot(2, 2, 1) # 2 rows, 2 columns, 1st subplot = top left\n", "plt.subplot(2, 2, 1) # 2 rows, 2 columns, 1st subplot = top left\n",
@ -418,9 +372,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 18,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.subplot2grid((3,3), (0, 0), rowspan=2, colspan=2)\n", "plt.subplot2grid((3,3), (0, 0), rowspan=2, colspan=2)\n",
@ -453,7 +405,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 19,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -494,9 +445,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 20,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import this" "import this"
@ -513,7 +462,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 21,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -556,9 +504,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 22,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = np.linspace(-1.5, 1.5, 30)\n", "x = np.linspace(-1.5, 1.5, 30)\n",
@ -588,9 +534,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 23,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.plot(x, x**2, px, py, \"ro\")\n", "plt.plot(x, x**2, px, py, \"ro\")\n",
@ -611,7 +555,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 24,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": false "scrolled": false
}, },
"outputs": [], "outputs": [],
@ -637,9 +580,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": 25,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with plt.xkcd():\n", "with plt.xkcd():\n",
@ -665,9 +606,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": 26,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = np.linspace(-1.4, 1.4, 50)\n", "x = np.linspace(-1.4, 1.4, 50)\n",
@ -690,7 +629,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 27,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -739,9 +677,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 28,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = np.linspace(-2, 2, 100)\n", "x = np.linspace(-2, 2, 100)\n",
@ -784,9 +720,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": 29,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"radius = 1\n", "radius = 1\n",
@ -811,7 +745,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 30, "execution_count": 30,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -840,9 +773,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": 31,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.contourf(X, Y, Z, cmap=matplotlib.cm.coolwarm)\n", "plt.contourf(X, Y, Z, cmap=matplotlib.cm.coolwarm)\n",
@ -867,9 +798,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": 32,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from numpy.random import rand\n", "from numpy.random import rand\n",
@ -888,9 +817,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": 33,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x, y, scale = rand(3, 100)\n", "x, y, scale = rand(3, 100)\n",
@ -910,7 +837,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": 34,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -938,9 +864,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 35,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from numpy.random import randn\n", "from numpy.random import randn\n",
@ -971,9 +895,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 36,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"data = [1, 1.1, 1.8, 2, 2.1, 3.2, 3, 3, 3, 3]\n", "data = [1, 1.1, 1.8, 2, 2.1, 3.2, 3, 3, 3, 3]\n",
@ -992,7 +914,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 37,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -1028,9 +949,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 38,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import matplotlib.image as mpimg\n", "import matplotlib.image as mpimg\n",
@ -1049,9 +968,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 39,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.imshow(img)\n", "plt.imshow(img)\n",
@ -1068,9 +985,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 40,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"plt.imshow(img)\n", "plt.imshow(img)\n",
@ -1088,9 +1003,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 41,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"img = np.arange(100*100).reshape(100, 100)\n", "img = np.arange(100*100).reshape(100, 100)\n",
@ -1110,7 +1023,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 42,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": false "scrolled": false
}, },
"outputs": [], "outputs": [],
@ -1130,7 +1042,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 43,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
@ -1155,7 +1066,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 44, "execution_count": 44,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": false "scrolled": false
}, },
"outputs": [], "outputs": [],
@ -1198,9 +1108,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 46,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = np.linspace(-1, 1, 100)\n", "x = np.linspace(-1, 1, 100)\n",
@ -1234,9 +1142,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 47,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"Writer = animation.writers['ffmpeg']\n", "Writer = animation.writers['ffmpeg']\n",
@ -1255,21 +1161,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.11" "version": "3.7.4"
}, },
"toc": { "toc": {
"toc_cell": true, "toc_cell": true,
@ -1280,5 +1186,5 @@
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

File diff suppressed because it is too large Load Diff

View File

@ -16,24 +16,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Setup\n", "# Setup"
"First, let's make sure this notebook works well in both python 2 and 3:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division, print_function, unicode_literals"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now let's import `pandas`. People usually import it as `pd`:" "First, let's import `pandas`. People usually import it as `pd`:"
] ]
}, },
{ {
@ -2817,7 +2807,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.7.4"
}, },
"toc": { "toc": {
"toc_cell": false, "toc_cell": false,