diff --git a/extra_gradient_descent_comparison.ipynb b/extra_gradient_descent_comparison.ipynb index 053ffd2..ee5ed6e 100644 --- a/extra_gradient_descent_comparison.ipynb +++ b/extra_gradient_descent_comparison.ipynb @@ -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", diff --git a/math_linear_algebra.ipynb b/math_linear_algebra.ipynb index 0718eff..e281e26 100644 --- a/math_linear_algebra.ipynb +++ b/math_linear_algebra.ipynb @@ -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": {}, diff --git a/tools_matplotlib.ipynb b/tools_matplotlib.ipynb index e2aba24..992f0cd 100644 --- a/tools_matplotlib.ipynb +++ b/tools_matplotlib.ipynb @@ -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 } diff --git a/tools_numpy.ipynb b/tools_numpy.ipynb index ed2d81b..06b00f2 100644 --- a/tools_numpy.ipynb +++ b/tools_numpy.ipynb @@ -8,19 +8,7 @@ "\n", "*NumPy is the fundamental library for scientific computing with Python. NumPy is centered around a powerful N-dimensional array object, and it also contains useful linear algebra, Fourier transform, and random number functions.*\n", "\n", - "# Creating arrays\n", - "First let's make sure that this notebook works both in python 2 and 3:" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "from __future__ import division, print_function, unicode_literals" + "# Creating arrays" ] }, { @@ -58,9 +46,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.zeros(5)" @@ -76,9 +62,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.zeros((3,4))" @@ -103,9 +87,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a = np.zeros((3,4))\n", @@ -115,9 +97,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a.shape" @@ -126,9 +106,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a.ndim # equal to len(a.shape)" @@ -137,9 +115,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a.size" @@ -156,9 +132,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.zeros((2,3,4))" @@ -175,9 +149,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "type(np.zeros((3,4)))" @@ -196,9 +168,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.ones((3,4))" @@ -215,9 +185,7 @@ { "cell_type": "code", "execution_count": 12, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.full((3,4), np.pi)" @@ -235,7 +203,6 @@ "cell_type": "code", "execution_count": 13, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -254,9 +221,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.array([[1,2,3,4], [10, 20, 30, 40]])" @@ -274,7 +239,6 @@ "cell_type": "code", "execution_count": 15, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -292,9 +256,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.arange(1.0, 5.0)" @@ -310,9 +272,7 @@ { "cell_type": "code", "execution_count": 17, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.arange(1, 5, 0.5)" @@ -328,9 +288,7 @@ { "cell_type": "code", "execution_count": 18, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "print(np.arange(0, 5/3, 1/3)) # depending on floating point errors, the max value is 4/3 or 5/3.\n", @@ -349,9 +307,7 @@ { "cell_type": "code", "execution_count": 19, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "print(np.linspace(0, 5/3, 6))" @@ -369,9 +325,7 @@ { "cell_type": "code", "execution_count": 20, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.random.rand(3,4)" @@ -387,9 +341,7 @@ { "cell_type": "code", "execution_count": 21, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.random.randn(3,4)" @@ -406,7 +358,6 @@ "cell_type": "code", "execution_count": 22, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], @@ -418,9 +369,7 @@ { "cell_type": "code", "execution_count": 23, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "plt.hist(np.random.rand(100000), normed=True, bins=100, histtype=\"step\", color=\"blue\", label=\"rand\")\n", @@ -444,9 +393,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "def my_function(z, y, x):\n", @@ -487,7 +434,6 @@ "cell_type": "code", "execution_count": 25, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -499,9 +445,7 @@ { "cell_type": "code", "execution_count": 26, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c = np.arange(1.0, 5.0)\n", @@ -518,9 +462,7 @@ { "cell_type": "code", "execution_count": 27, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "d = np.arange(1, 5, dtype=np.complex64)\n", @@ -540,9 +482,7 @@ { "cell_type": "code", "execution_count": 28, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "e = np.arange(1, 5, dtype=np.complex64)\n", @@ -561,7 +501,6 @@ "cell_type": "code", "execution_count": 29, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], @@ -580,9 +519,7 @@ { "cell_type": "code", "execution_count": 30, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "if (hasattr(f.data, \"tobytes\")):\n", @@ -612,9 +549,7 @@ { "cell_type": "code", "execution_count": 31, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "g = np.arange(24)\n", @@ -625,9 +560,7 @@ { "cell_type": "code", "execution_count": 32, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "g.shape = (6, 4)\n", @@ -639,7 +572,6 @@ "cell_type": "code", "execution_count": 33, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -661,7 +593,6 @@ "cell_type": "code", "execution_count": 34, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -681,9 +612,7 @@ { "cell_type": "code", "execution_count": 35, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "g2[1, 2] = 999\n", @@ -700,9 +629,7 @@ { "cell_type": "code", "execution_count": 36, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "g" @@ -719,9 +646,7 @@ { "cell_type": "code", "execution_count": 37, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "g.ravel()" @@ -739,7 +664,6 @@ "cell_type": "code", "execution_count": 38, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], @@ -784,9 +708,7 @@ { "cell_type": "code", "execution_count": 39, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "h = np.arange(5).reshape(1, 1, 5)\n", @@ -803,9 +725,7 @@ { "cell_type": "code", "execution_count": 40, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "h + [10, 20, 30, 40, 50] # same as: h + [[[10, 20, 30, 40, 50]]]" @@ -822,9 +742,7 @@ { "cell_type": "code", "execution_count": 41, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k = np.arange(6).reshape(2, 3)\n", @@ -841,9 +759,7 @@ { "cell_type": "code", "execution_count": 42, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k + [[100], [200]] # same as: k + [[100, 100, 100], [200, 200, 200]]" @@ -859,9 +775,7 @@ { "cell_type": "code", "execution_count": 43, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k + [100, 200, 300] # after rule 1: [[100, 200, 300]], and after rule 2: [[100, 200, 300], [100, 200, 300]]" @@ -877,9 +791,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k + 1000 # same as: k + [[1000, 1000, 1000], [1000, 1000, 1000]]" @@ -896,9 +808,7 @@ { "cell_type": "code", "execution_count": 45, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "try:\n", @@ -926,9 +836,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k1 = np.arange(0, 5, dtype=np.uint8)\n", @@ -938,9 +846,7 @@ { "cell_type": "code", "execution_count": 47, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k2 = k1 + np.array([5, 6, 7, 8, 9], dtype=np.int8)\n", @@ -957,9 +863,7 @@ { "cell_type": "code", "execution_count": 48, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "k3 = k1 + 1.5\n", @@ -983,9 +887,7 @@ { "cell_type": "code", "execution_count": 49, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m = np.array([20, -5, 30, 40])\n", @@ -1002,9 +904,7 @@ { "cell_type": "code", "execution_count": 50, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m < 25 # equivalent to m < [25, 25, 25, 25]" @@ -1020,9 +920,7 @@ { "cell_type": "code", "execution_count": 51, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m[m < 25]" @@ -1048,9 +946,7 @@ { "cell_type": "code", "execution_count": 52, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a = np.array([[-2.5, 3.1, 7], [10, 11, 12]])\n", @@ -1070,9 +966,7 @@ { "cell_type": "code", "execution_count": 53, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "for func in (a.min, a.max, a.sum, a.prod, a.std, a.var):\n", @@ -1089,9 +983,7 @@ { "cell_type": "code", "execution_count": 54, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c=np.arange(24).reshape(2,3,4)\n", @@ -1101,9 +993,7 @@ { "cell_type": "code", "execution_count": 55, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c.sum(axis=0) # sum across matrices" @@ -1112,9 +1002,7 @@ { "cell_type": "code", "execution_count": 56, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c.sum(axis=1) # sum across rows" @@ -1130,9 +1018,7 @@ { "cell_type": "code", "execution_count": 57, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c.sum(axis=(0,2)) # sum across matrices and columns" @@ -1141,9 +1027,7 @@ { "cell_type": "code", "execution_count": 58, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "0+1+2+3 + 12+13+14+15, 4+5+6+7 + 16+17+18+19, 8+9+10+11 + 20+21+22+23" @@ -1160,9 +1044,7 @@ { "cell_type": "code", "execution_count": 59, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a = np.array([[-2.5, 3.1, 7], [10, 11, 12]])\n", @@ -1179,9 +1061,7 @@ { "cell_type": "code", "execution_count": 60, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "print(\"Original ndarray\")\n", @@ -1202,9 +1082,7 @@ { "cell_type": "code", "execution_count": 61, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a = np.array([1, -2, 3, 4])\n", @@ -1215,9 +1093,7 @@ { "cell_type": "code", "execution_count": 62, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.greater(a, b) # equivalent to a > b" @@ -1226,9 +1102,7 @@ { "cell_type": "code", "execution_count": 63, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.maximum(a, b)" @@ -1237,9 +1111,7 @@ { "cell_type": "code", "execution_count": 64, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.copysign(a, b)" @@ -1257,9 +1129,7 @@ { "cell_type": "code", "execution_count": 65, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a = np.array([1, 5, 3, 19, 13, 7, 3])\n", @@ -1269,9 +1139,7 @@ { "cell_type": "code", "execution_count": 66, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[2:5]" @@ -1280,9 +1148,7 @@ { "cell_type": "code", "execution_count": 67, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[2:-1]" @@ -1291,9 +1157,7 @@ { "cell_type": "code", "execution_count": 68, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[:2]" @@ -1302,9 +1166,7 @@ { "cell_type": "code", "execution_count": 69, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[2::2]" @@ -1313,9 +1175,7 @@ { "cell_type": "code", "execution_count": 70, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[::-1]" @@ -1331,9 +1191,7 @@ { "cell_type": "code", "execution_count": 71, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[3]=999\n", @@ -1350,9 +1208,7 @@ { "cell_type": "code", "execution_count": 72, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[2:5] = [997, 998, 999]\n", @@ -1370,9 +1226,7 @@ { "cell_type": "code", "execution_count": 73, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[2:5] = -1\n", @@ -1390,7 +1244,6 @@ "cell_type": "code", "execution_count": 74, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], @@ -1411,9 +1264,7 @@ { "cell_type": "code", "execution_count": 75, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "try:\n", @@ -1432,9 +1283,7 @@ { "cell_type": "code", "execution_count": 76, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a_slice = a[2:6]\n", @@ -1445,9 +1294,7 @@ { "cell_type": "code", "execution_count": 77, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[3] = 2000\n", @@ -1464,9 +1311,7 @@ { "cell_type": "code", "execution_count": 78, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "another_slice = a[2:6].copy()\n", @@ -1477,9 +1322,7 @@ { "cell_type": "code", "execution_count": 79, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a[3] = 4000\n", @@ -1497,9 +1340,7 @@ { "cell_type": "code", "execution_count": 80, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b = np.arange(48).reshape(4, 12)\n", @@ -1509,9 +1350,7 @@ { "cell_type": "code", "execution_count": 81, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[1, 2] # row 1, col 2" @@ -1520,9 +1359,7 @@ { "cell_type": "code", "execution_count": 82, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[1, :] # row 1, all columns" @@ -1531,9 +1368,7 @@ { "cell_type": "code", "execution_count": 83, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[:, 1] # all rows, column 1" @@ -1550,7 +1385,6 @@ "cell_type": "code", "execution_count": 84, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -1561,9 +1395,7 @@ { "cell_type": "code", "execution_count": 85, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[1:2, :]" @@ -1588,7 +1420,6 @@ "cell_type": "code", "execution_count": 86, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -1599,9 +1430,7 @@ { "cell_type": "code", "execution_count": 87, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[:, (-1, 2, -1)] # all rows, columns -1 (last), 2 and -1 (again, and in this order)" @@ -1617,9 +1446,7 @@ { "cell_type": "code", "execution_count": 88, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[(-1, 2, -1, 2), (5, 9, 1, 9)] # returns a 1D array with b[-1, 5], b[2, 9], b[-1, 1] and b[2, 9] (again)" @@ -1636,9 +1463,7 @@ { "cell_type": "code", "execution_count": 89, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c = b.reshape(4,2,6)\n", @@ -1648,9 +1473,7 @@ { "cell_type": "code", "execution_count": 90, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, 1, 4] # matrix 2, row 1, col 4" @@ -1659,9 +1482,7 @@ { "cell_type": "code", "execution_count": 91, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, :, 3] # matrix 2, all rows, col 3" @@ -1677,9 +1498,7 @@ { "cell_type": "code", "execution_count": 92, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, 1] # Return matrix 2, row 1, all columns. This is equivalent to c[2, 1, :]" @@ -1696,9 +1515,7 @@ { "cell_type": "code", "execution_count": 93, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, ...] # matrix 2, all rows, all columns. This is equivalent to c[2, :, :]" @@ -1707,9 +1524,7 @@ { "cell_type": "code", "execution_count": 94, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, 1, ...] # matrix 2, row 1, all columns. This is equivalent to c[2, 1, :]" @@ -1718,9 +1533,7 @@ { "cell_type": "code", "execution_count": 95, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c[2, ..., 3] # matrix 2, all rows, column 3. This is equivalent to c[2, :, 3]" @@ -1730,7 +1543,6 @@ "cell_type": "code", "execution_count": 96, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [], @@ -1749,9 +1561,7 @@ { "cell_type": "code", "execution_count": 97, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b = np.arange(48).reshape(4, 12)\n", @@ -1761,9 +1571,7 @@ { "cell_type": "code", "execution_count": 98, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "rows_on = np.array([True, False, True, False])\n", @@ -1773,9 +1581,7 @@ { "cell_type": "code", "execution_count": 99, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "cols_on = np.array([False, True, False] * 4)\n", @@ -1793,9 +1599,7 @@ { "cell_type": "code", "execution_count": 100, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[np.ix_(rows_on, cols_on)]" @@ -1804,9 +1608,7 @@ { "cell_type": "code", "execution_count": 101, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.ix_(rows_on, cols_on)" @@ -1822,9 +1624,7 @@ { "cell_type": "code", "execution_count": 102, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b[b % 3 == 1]" @@ -1841,9 +1641,7 @@ { "cell_type": "code", "execution_count": 103, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "c = np.arange(24).reshape(2, 3, 4) # A 3D array (composed of two 3x4 matrices)\n", @@ -1853,9 +1651,7 @@ { "cell_type": "code", "execution_count": 104, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "for m in c:\n", @@ -1866,9 +1662,7 @@ { "cell_type": "code", "execution_count": 105, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "for i in range(len(c)): # Note that len(c) == c.shape[0]\n", @@ -1886,9 +1680,7 @@ { "cell_type": "code", "execution_count": 106, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "for i in c.flat:\n", @@ -1906,9 +1698,7 @@ { "cell_type": "code", "execution_count": 107, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q1 = np.full((3,4), 1.0)\n", @@ -1918,9 +1708,7 @@ { "cell_type": "code", "execution_count": 108, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q2 = np.full((4,4), 2.0)\n", @@ -1930,9 +1718,7 @@ { "cell_type": "code", "execution_count": 109, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q3 = np.full((3,4), 3.0)\n", @@ -1950,9 +1736,7 @@ { "cell_type": "code", "execution_count": 110, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q4 = np.vstack((q1, q2, q3))\n", @@ -1962,9 +1746,7 @@ { "cell_type": "code", "execution_count": 111, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q4.shape" @@ -1983,9 +1765,7 @@ { "cell_type": "code", "execution_count": 112, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q5 = np.hstack((q1, q3))\n", @@ -1995,9 +1775,7 @@ { "cell_type": "code", "execution_count": 113, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q5.shape" @@ -2013,9 +1791,7 @@ { "cell_type": "code", "execution_count": 114, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "try:\n", @@ -2035,9 +1811,7 @@ { "cell_type": "code", "execution_count": 115, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q7 = np.concatenate((q1, q2, q3), axis=0) # Equivalent to vstack\n", @@ -2047,9 +1821,7 @@ { "cell_type": "code", "execution_count": 116, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q7.shape" @@ -2073,9 +1845,7 @@ { "cell_type": "code", "execution_count": 117, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q8 = np.stack((q1, q3))\n", @@ -2085,9 +1855,7 @@ { "cell_type": "code", "execution_count": 118, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q8.shape" @@ -2106,9 +1874,7 @@ { "cell_type": "code", "execution_count": 119, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r = np.arange(24).reshape(6,4)\n", @@ -2125,9 +1891,7 @@ { "cell_type": "code", "execution_count": 120, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r1, r2, r3 = np.vsplit(r, 3)\n", @@ -2137,9 +1901,7 @@ { "cell_type": "code", "execution_count": 121, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r2" @@ -2148,9 +1910,7 @@ { "cell_type": "code", "execution_count": 122, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r3" @@ -2166,9 +1926,7 @@ { "cell_type": "code", "execution_count": 123, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r4, r5 = np.hsplit(r, 2)\n", @@ -2178,9 +1936,7 @@ { "cell_type": "code", "execution_count": 124, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r5" @@ -2199,9 +1955,7 @@ { "cell_type": "code", "execution_count": 125, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t = np.arange(24).reshape(4,2,3)\n", @@ -2218,9 +1972,7 @@ { "cell_type": "code", "execution_count": 126, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t1 = t.transpose((1,2,0))\n", @@ -2230,9 +1982,7 @@ { "cell_type": "code", "execution_count": 127, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t1.shape" @@ -2248,9 +1998,7 @@ { "cell_type": "code", "execution_count": 128, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t2 = t.transpose() # equivalent to t.transpose((2, 1, 0))\n", @@ -2260,9 +2008,7 @@ { "cell_type": "code", "execution_count": 129, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t2.shape" @@ -2278,9 +2024,7 @@ { "cell_type": "code", "execution_count": 130, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t3 = t.swapaxes(0,1) # equivalent to t.transpose((1, 0, 2))\n", @@ -2290,9 +2034,7 @@ { "cell_type": "code", "execution_count": 131, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "t3.shape" @@ -2312,9 +2054,7 @@ { "cell_type": "code", "execution_count": 132, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m1 = np.arange(10).reshape(2,5)\n", @@ -2324,9 +2064,7 @@ { "cell_type": "code", "execution_count": 133, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m1.T" @@ -2343,7 +2081,6 @@ "cell_type": "code", "execution_count": 134, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -2356,7 +2093,6 @@ "cell_type": "code", "execution_count": 135, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -2374,9 +2110,7 @@ { "cell_type": "code", "execution_count": 136, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m2r = m2.reshape(1,5)\n", @@ -2386,9 +2120,7 @@ { "cell_type": "code", "execution_count": 137, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m2r.T" @@ -2405,9 +2137,7 @@ { "cell_type": "code", "execution_count": 138, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "n1 = np.arange(10).reshape(2, 5)\n", @@ -2417,9 +2147,7 @@ { "cell_type": "code", "execution_count": 139, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "n2 = np.arange(15).reshape(5,3)\n", @@ -2429,9 +2157,7 @@ { "cell_type": "code", "execution_count": 140, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "n1.dot(n2)" @@ -2455,9 +2181,7 @@ { "cell_type": "code", "execution_count": 141, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import numpy.linalg as linalg\n", @@ -2469,9 +2193,7 @@ { "cell_type": "code", "execution_count": 142, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "linalg.inv(m3)" @@ -2487,9 +2209,7 @@ { "cell_type": "code", "execution_count": 143, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "linalg.pinv(m3)" @@ -2506,9 +2226,7 @@ { "cell_type": "code", "execution_count": 144, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m3.dot(linalg.inv(m3))" @@ -2524,9 +2242,7 @@ { "cell_type": "code", "execution_count": 145, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.eye(3)" @@ -2543,9 +2259,7 @@ { "cell_type": "code", "execution_count": 146, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q, r = linalg.qr(m3)\n", @@ -2555,9 +2269,7 @@ { "cell_type": "code", "execution_count": 147, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "r" @@ -2566,9 +2278,7 @@ { "cell_type": "code", "execution_count": 148, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "q.dot(r) # q.r equals m3" @@ -2585,9 +2295,7 @@ { "cell_type": "code", "execution_count": 149, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "linalg.det(m3) # Computes the matrix determinant" @@ -2604,9 +2312,7 @@ { "cell_type": "code", "execution_count": 150, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "eigenvalues, eigenvectors = linalg.eig(m3)\n", @@ -2616,9 +2322,7 @@ { "cell_type": "code", "execution_count": 151, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "eigenvectors # v" @@ -2627,9 +2331,7 @@ { "cell_type": "code", "execution_count": 152, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m3.dot(eigenvectors) - eigenvalues * eigenvectors # m3.v - λ*v = 0" @@ -2646,9 +2348,7 @@ { "cell_type": "code", "execution_count": 153, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "m4 = np.array([[1,0,0,0,2], [0,0,3,0,0], [0,0,0,0,0], [0,2,0,0,0]])\n", @@ -2658,9 +2358,7 @@ { "cell_type": "code", "execution_count": 154, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "U, S_diag, V = linalg.svd(m4)\n", @@ -2670,9 +2368,7 @@ { "cell_type": "code", "execution_count": 155, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "S_diag" @@ -2688,9 +2384,7 @@ { "cell_type": "code", "execution_count": 156, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "S = np.zeros((4, 5))\n", @@ -2701,9 +2395,7 @@ { "cell_type": "code", "execution_count": 157, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "V" @@ -2712,9 +2404,7 @@ { "cell_type": "code", "execution_count": 158, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "U.dot(S).dot(V) # U.Σ.V == m4" @@ -2730,9 +2420,7 @@ { "cell_type": "code", "execution_count": 159, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.diag(m3) # the values in the diagonal of m3 (top left to bottom right)" @@ -2741,9 +2429,7 @@ { "cell_type": "code", "execution_count": 160, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.trace(m3) # equivalent to np.diag(m3).sum()" @@ -2769,9 +2455,7 @@ { "cell_type": "code", "execution_count": 161, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "coeffs = np.array([[2, 6], [5, 3]])\n", @@ -2790,9 +2474,7 @@ { "cell_type": "code", "execution_count": 162, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "coeffs.dot(solution), depvars # yep, it's the same" @@ -2809,7 +2491,6 @@ "cell_type": "code", "execution_count": 163, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -2830,9 +2511,7 @@ { "cell_type": "code", "execution_count": 164, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import math\n", @@ -2852,9 +2531,7 @@ { "cell_type": "code", "execution_count": 165, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "x_coords = np.arange(0, 1024) # [0, 1, 2, ..., 1023]\n", @@ -2866,9 +2543,7 @@ { "cell_type": "code", "execution_count": 166, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "Y" @@ -2886,9 +2561,7 @@ { "cell_type": "code", "execution_count": 167, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "data = np.sin(X*Y/40.5)" @@ -2904,9 +2577,7 @@ { "cell_type": "code", "execution_count": 168, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -2931,7 +2602,6 @@ "cell_type": "code", "execution_count": 169, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [], @@ -2943,9 +2613,7 @@ { "cell_type": "code", "execution_count": 170, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.save(\"my_array\", a)" @@ -2961,9 +2629,7 @@ { "cell_type": "code", "execution_count": 171, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "with open(\"my_array.npy\", \"rb\") as f:\n", @@ -2982,9 +2648,7 @@ { "cell_type": "code", "execution_count": 172, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a_loaded = np.load(\"my_array.npy\")\n", @@ -3002,9 +2666,7 @@ { "cell_type": "code", "execution_count": 173, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "np.savetxt(\"my_array.csv\", a)" @@ -3020,9 +2682,7 @@ { "cell_type": "code", "execution_count": 174, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "with open(\"my_array.csv\", \"rt\") as f:\n", @@ -3057,9 +2717,7 @@ { "cell_type": "code", "execution_count": 176, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "a_loaded = np.loadtxt(\"my_array.csv\", delimiter=\",\")\n", @@ -3077,9 +2735,7 @@ { "cell_type": "code", "execution_count": 177, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "b = np.arange(24, dtype=np.uint8).reshape(2, 3, 4)\n", @@ -3107,9 +2763,7 @@ { "cell_type": "code", "execution_count": 179, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "with open(\"my_arrays.npz\", \"rb\") as f:\n", @@ -3128,9 +2782,7 @@ { "cell_type": "code", "execution_count": 180, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "my_arrays = np.load(\"my_arrays.npz\")\n", @@ -3147,9 +2799,7 @@ { "cell_type": "code", "execution_count": 181, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "my_arrays.keys()" @@ -3158,9 +2808,7 @@ { "cell_type": "code", "execution_count": 182, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "my_arrays[\"my_a\"]" @@ -3177,21 +2825,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": false, @@ -3209,5 +2857,5 @@ } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/tools_pandas.ipynb b/tools_pandas.ipynb index 6580f20..8c11356 100644 --- a/tools_pandas.ipynb +++ b/tools_pandas.ipynb @@ -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,