Commit a9648fc8 authored by Inigo Aldazabal's avatar Inigo Aldazabal

refreshed notebook

parent 52328bd7
...@@ -79,7 +79,9 @@ ...@@ -79,7 +79,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
...@@ -120,7 +122,9 @@ ...@@ -120,7 +122,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"L = range(1000)" "L = range(1000)"
...@@ -129,7 +133,9 @@ ...@@ -129,7 +133,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%timeit [ i**2 for i in L ]" "%timeit [ i**2 for i in L ]"
...@@ -138,7 +144,9 @@ ...@@ -138,7 +144,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(1000)" "a = np.arange(1000)"
...@@ -147,7 +155,9 @@ ...@@ -147,7 +155,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%timeit a**2" "%timeit a**2"
...@@ -172,7 +182,9 @@ ...@@ -172,7 +182,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.array # SHIFT+TAB" "np.array # SHIFT+TAB"
...@@ -189,6 +201,7 @@ ...@@ -189,6 +201,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": true,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
...@@ -199,7 +212,9 @@ ...@@ -199,7 +212,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.con # TAB completion" "np.con # TAB completion"
...@@ -222,7 +237,9 @@ ...@@ -222,7 +237,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np" "import numpy as np"
...@@ -252,7 +269,9 @@ ...@@ -252,7 +269,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.array([0, 1, 2, 3])\n", "a = np.array([0, 1, 2, 3])\n",
...@@ -262,7 +281,9 @@ ...@@ -262,7 +281,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a.ndim" "a.ndim"
...@@ -271,7 +292,9 @@ ...@@ -271,7 +292,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a.shape" "a.shape"
...@@ -280,7 +303,9 @@ ...@@ -280,7 +303,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"len(a)" "len(a)"
...@@ -296,7 +321,9 @@ ...@@ -296,7 +321,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.array([[0, 1, 2], [3, 4, 5]]) # 2 x 3 array\n", "b = np.array([[0, 1, 2], [3, 4, 5]]) # 2 x 3 array\n",
...@@ -306,7 +333,9 @@ ...@@ -306,7 +333,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b.ndim" "b.ndim"
...@@ -315,7 +344,9 @@ ...@@ -315,7 +344,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b.shape # notice row-column order" "b.shape # notice row-column order"
...@@ -324,7 +355,9 @@ ...@@ -324,7 +355,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"len(b) # returns the size of the first dimension" "len(b) # returns the size of the first dimension"
...@@ -372,7 +405,9 @@ ...@@ -372,7 +405,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(10) # 0 .. n-1\n", "a = np.arange(10) # 0 .. n-1\n",
...@@ -382,7 +417,9 @@ ...@@ -382,7 +417,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.arange(1, 9, 2) # start, end (exclusive), step\n", "b = np.arange(1, 9, 2) # start, end (exclusive), step\n",
...@@ -399,7 +436,9 @@ ...@@ -399,7 +436,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"c = np.linspace(0, 1, 6) # start, end, num-points\n", "c = np.linspace(0, 1, 6) # start, end, num-points\n",
...@@ -409,7 +448,9 @@ ...@@ -409,7 +448,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"d = np.linspace(0, 1, 5, endpoint=False)\n", "d = np.linspace(0, 1, 5, endpoint=False)\n",
...@@ -426,7 +467,9 @@ ...@@ -426,7 +467,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.ones((3, 3))\n", "a = np.ones((3, 3))\n",
...@@ -436,7 +479,9 @@ ...@@ -436,7 +479,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.zeros((2, 2))\n", "b = np.zeros((2, 2))\n",
...@@ -446,7 +491,9 @@ ...@@ -446,7 +491,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"c = np.eye(3)\n", "c = np.eye(3)\n",
...@@ -456,7 +503,9 @@ ...@@ -456,7 +503,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.diag([1, 2, 3, 4])" "np.diag([1, 2, 3, 4])"
...@@ -472,7 +521,9 @@ ...@@ -472,7 +521,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.random.rand(4) # uniform in [0, 1] \n", "a = np.random.rand(4) # uniform in [0, 1] \n",
...@@ -482,7 +533,9 @@ ...@@ -482,7 +533,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.random.randn(4) # Gaussian\n", "b = np.random.randn(4) # Gaussian\n",
...@@ -534,7 +587,9 @@ ...@@ -534,7 +587,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
...@@ -545,7 +600,9 @@ ...@@ -545,7 +600,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"2**a" "2**a"
...@@ -561,7 +618,9 @@ ...@@ -561,7 +618,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.ones(4) + 1\n", "b = np.ones(4) + 1\n",
...@@ -571,7 +630,9 @@ ...@@ -571,7 +630,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a * b" "a * b"
...@@ -594,7 +655,9 @@ ...@@ -594,7 +655,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"c = np.ones((3, 3))\n", "c = np.ones((3, 3))\n",
...@@ -618,7 +681,9 @@ ...@@ -618,7 +681,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# python 2 and 3\n", "# python 2 and 3\n",
...@@ -628,7 +693,9 @@ ...@@ -628,7 +693,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"c @ c" "c @ c"
...@@ -659,7 +726,9 @@ ...@@ -659,7 +726,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.ones(4)*2\n", "a = np.ones(4)*2\n",
...@@ -670,7 +739,9 @@ ...@@ -670,7 +739,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a_j = a**(3.*b) - b\n", "a_j = a**(3.*b) - b\n",
...@@ -694,7 +765,9 @@ ...@@ -694,7 +765,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.array([1, 2, 3, 4])\n", "a = np.array([1, 2, 3, 4])\n",
...@@ -706,7 +779,9 @@ ...@@ -706,7 +779,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a > b" "a > b"
...@@ -723,6 +798,7 @@ ...@@ -723,6 +798,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": true,
"scrolled": true "scrolled": true
}, },
"outputs": [], "outputs": [],
...@@ -734,7 +810,9 @@ ...@@ -734,7 +810,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.log(a)" "np.log(a)"
...@@ -743,7 +821,9 @@ ...@@ -743,7 +821,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.exp(a)" "np.exp(a)"
...@@ -759,7 +839,9 @@ ...@@ -759,7 +839,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(4)\n", "a = np.arange(4)\n",
...@@ -776,7 +858,9 @@ ...@@ -776,7 +858,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"A = np.random.rand(3, 3)\n", "A = np.random.rand(3, 3)\n",
...@@ -786,7 +870,9 @@ ...@@ -786,7 +870,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"A.T" "A.T"
...@@ -851,7 +937,9 @@ ...@@ -851,7 +937,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(10)\n", "a = np.arange(10)\n",
...@@ -861,7 +949,9 @@ ...@@ -861,7 +949,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[0], a[2], a[-1]" "a[0], a[2], a[-1]"
...@@ -892,7 +982,9 @@ ...@@ -892,7 +982,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[::-1] # start:end:step" "a[::-1] # start:end:step"
...@@ -908,7 +1000,9 @@ ...@@ -908,7 +1000,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.diag(np.arange(3))\n", "a = np.diag(np.arange(3))\n",
...@@ -918,7 +1012,9 @@ ...@@ -918,7 +1012,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[1, 1]" "a[1, 1]"
...@@ -927,7 +1023,9 @@ ...@@ -927,7 +1023,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[2, 1] = 10 # third line, second column\n", "a[2, 1] = 10 # third line, second column\n",
...@@ -937,7 +1035,9 @@ ...@@ -937,7 +1035,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[1] # row wise" "a[1] # row wise"
...@@ -975,7 +1075,9 @@ ...@@ -975,7 +1075,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(10)\n", "a = np.arange(10)\n",
...@@ -985,7 +1087,9 @@ ...@@ -985,7 +1087,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[2:9:3] # start:end:step" "a[2:9:3] # start:end:step"
...@@ -1001,7 +1105,9 @@ ...@@ -1001,7 +1105,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[:4]" "a[:4]"
...@@ -1018,7 +1124,9 @@ ...@@ -1018,7 +1124,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[1:3]" "a[1:3]"
...@@ -1027,7 +1135,9 @@ ...@@ -1027,7 +1135,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[::2]" "a[::2]"
...@@ -1036,7 +1146,9 @@ ...@@ -1036,7 +1146,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a[3:]" "a[3:]"
...@@ -1052,7 +1164,9 @@ ...@@ -1052,7 +1164,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from IPython.display import Image\n", "from IPython.display import Image\n",
...@@ -1069,7 +1183,9 @@ ...@@ -1069,7 +1183,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = np.arange(10)\n", "a = np.arange(10)\n",
...@@ -1080,7 +1196,9 @@ ...@@ -1080,7 +1196,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"b = np.arange(5)\n", "b = np.arange(5)\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment