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": {},
"outputs": [],
"source": [
"from __future__ import print_function, division, unicode_literals\n",
"import numpy as np\n",
"\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.*"
]
},
{
"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",
"metadata": {},

View File

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