Commit bd7d498e authored by Inigo Aldazabal's avatar Inigo Aldazabal

Simplify exercicies and cleanup

parent dc4e1791
......@@ -89,7 +89,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For example, An array containing:\n"
"For example, a numpy array can contain:\n"
]
},
{
......@@ -187,7 +187,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [],
"source": []
......@@ -235,7 +235,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating arrays"
"## Creating and inspecting arrays"
]
},
{
......@@ -474,15 +474,6 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -568,15 +559,6 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -627,7 +609,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": []
......@@ -645,9 +627,7 @@
"source": [
"* Try simple arithmetic elementwise operations.\n",
"\n",
"* Time them against their pure python counterparts using `%timeit`.\n",
"\n",
"* Try using `dot`.\n",
"* Try using `dot` or `@` operator.\n",
"\n",
"* Generate:\n",
"\n",
......@@ -667,7 +647,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Comparisons:\n"
"#### Comparisons\n"
]
},
{
......@@ -692,14 +672,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Transcendental functions:\n"
"#### Transcendental functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": []
......@@ -726,7 +707,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Shape mismatches\n"
"#### Shape mismatches\n"
]
},
{
......@@ -742,7 +723,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Transposition:\n"
"#### Transposition"
]
},
{
......@@ -788,20 +769,6 @@
"section ``scipy_linalg``\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -815,24 +782,14 @@
"source": [
"* Look at the help for `np.allclose`. When might this be useful?\n",
"\n",
"* Look at the help for `np.triu` and `np.tril`.\n",
"\n",
"* Is the transpose a view or a copy? What implications does this have for\n",
"making a matrix symmetric?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic visualization"
"* Look at the help for `np.triu` and `np.tril`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tip"
"## Basic matplotlib visualization"
]
},
{
......@@ -914,6 +871,15 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -941,9 +907,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"* Plot some simple arrays.\n",
"\n",
"* Try to use both the IPython shell and the notebook, if possible.\n",
"* Plot some simple arrays / functions.\n",
"\n",
"* Try using the `gray` colormap.\n"
]
......@@ -1091,9 +1055,7 @@
"collapsed": false
},
"outputs": [],
"source": [
"a = np"
]
"source": []
},
{
"cell_type": "code",
......@@ -1164,7 +1126,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"collapsed": false
},
......@@ -1176,7 +1138,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1210,6 +1172,15 @@
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
......
......@@ -85,7 +85,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"a = np.array([0, 1, 2, 3])\n",
"a = np.array( [0, 1, 2, 3])\n",
"a"
]
},
......@@ -93,7 +93,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For example, An array containing:\n"
"For example, a numpy array can contain:\n"
]
},
{
......@@ -127,7 +127,7 @@
},
"outputs": [],
"source": [
"L=range(1000)"
"L = range(1000)"
]
},
{
......@@ -138,14 +138,14 @@
},
"outputs": [],
"source": [
"%timeit [i**2 for i in L]"
"%timeit [ i**2 for i in L ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
......@@ -183,11 +183,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [],
"source": [
"np.array?"
"np.array? # SHIFT+TAB"
]
},
{
......@@ -201,7 +201,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [],
"source": [
......@@ -212,11 +212,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": true
},
"outputs": [],
"source": [
"np.con*?"
"np.con # TAB completion"
]
},
{
......@@ -255,7 +255,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating arrays"
"## Creating and inspecting arrays"
]
},
{
......@@ -325,7 +325,7 @@
},
"outputs": [],
"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",
"b"
]
},
......@@ -348,7 +348,7 @@
},
"outputs": [],
"source": [
"b.shape"
"b.shape # notice row-column order"
]
},
{
......@@ -359,7 +359,7 @@
},
"outputs": [],
"source": [
"len(b) # returns the size of the first dimension"
"len(b) # returns the size of the first dimension"
]
},
{
......@@ -421,7 +421,7 @@
},
"outputs": [],
"source": [
"b = np.arange(1, 9, 2) # start, end (exclusive), step\n",
"b = np.arange(1, 9, 2) # start, end (exclusive), step\n",
"b"
]
},
......@@ -507,7 +507,7 @@
},
"outputs": [],
"source": [
"np.diag(np.array([1, 2, 3, 4]))"
"np.diag([1, 2, 3, 4])"
]
},
{
......@@ -525,7 +525,7 @@
},
"outputs": [],
"source": [
"a = np.random.rand(4) # uniform in [0, 1]\n",
"a = np.random.rand(4) # uniform in [0, 1] \n",
"a"
]
},
......@@ -537,7 +537,7 @@
},
"outputs": [],
"source": [
"b = np.random.randn(4) # Gaussian\n",
"b = np.random.randn(4) # Gaussian\n",
"b"
]
},
......@@ -623,7 +623,7 @@
"outputs": [],
"source": [
"b = np.ones(4) + 1\n",
"a - b "
"a - b"
]
},
{
......@@ -660,7 +660,7 @@
"outputs": [],
"source": [
"c = np.ones((3, 3))\n",
"c * c"
"c *c "
]
},
{
......@@ -686,18 +686,17 @@
"outputs": [],
"source": [
"# python 2 and 3\n",
"np.dot(c, c)"
"np.dot(c,c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
"# python 3\n",
"c @ c"
]
},
......@@ -714,9 +713,7 @@
"source": [
"* Try simple arithmetic elementwise operations.\n",
"\n",
"* Time them against their pure python counterparts using `%timeit`.\n",
"\n",
"* Try using `dot`.\n",
"* Try using `dot` or `@` operator.\n",
"\n",
"* Generate:\n",
"\n",
......@@ -736,7 +733,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Comparisons:\n"
"#### Comparisons:\n"
]
},
{
......@@ -748,7 +745,7 @@
"outputs": [],
"source": [
"a = np.array([1, 2, 3, 4])\n",
"b = np.array([4, 2, 2, 4])\n",
"b= np.array([4, 2, 2, 4])\n",
"\n",
"a == b"
]
......@@ -768,18 +765,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Transcendental functions:\n"
"#### Transcendental functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"a = np.arange(10)\n",
"a = np.linspace(0, 2.*np.pi, 10)\n",
"np.sin(a)"
]
},
......@@ -809,7 +807,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Shape mismatches\n"
"#### Shape mismatches"
]
},
{
......@@ -828,7 +826,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Transposition:\n"
"#### Transposition\n"
]
},
{
......@@ -839,8 +837,8 @@
},
"outputs": [],
"source": [
"a = np.random.rand(3,3)\n",
"a"
"A = np.random.rand(3, 3)\n",
"A"
]
},
{
......@@ -851,7 +849,7 @@
},
"outputs": [],
"source": [
"a.T"
"A.T"
]
},
{
......@@ -865,7 +863,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Linear algebra**\n"
"**Linear algebra**"
]
},
{
......@@ -879,13 +877,6 @@
"section ``scipy_linalg``\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -899,24 +890,14 @@
"source": [
"* Look at the help for `np.allclose`. When might this be useful?\n",
"\n",
"* Look at the help for `np.triu` and `np.tril`.\n",
"\n",
"* Is the transpose a view or a copy? What implications does this have for\n",
"making a matrix symmetric?\n"
"* Look at the help for `np.triu` and `np.tril`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tip"
"## Basic matplotlib visualization"
]
},
{
......@@ -994,7 +975,7 @@
"source": [
"x = np.linspace(0, 4.*np.pi, 100)\n",
"y = np.sin(x)\n",
"plt.plot(x, y) # line plot"
"plt.plot(x, y) # line plot"
]
},
{
......@@ -1005,7 +986,7 @@
},
"outputs": [],
"source": [
"plt.plot(x, y, 'o') # dot plot"
"plt.plot(x, y, 'o') # dot plot"
]
},
{
......@@ -1050,9 +1031,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"* Plot some simple arrays.\n",
"\n",
"* Try to use both the IPython shell and the notebook, if possible.\n",
"* Plot some simple arrays / functions.\n",
"\n",
"* Try using the `gray` colormap.\n"
]
......@@ -1125,7 +1104,7 @@
},
"outputs": [],
"source": [
"a[::-1]"
"a[::-1] # start:end:step"
]
},
{
......@@ -1178,7 +1157,7 @@
},
"outputs": [],
"source": [
"a[1]"
"a[1] # row wise"
]
},
{
......@@ -1205,7 +1184,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Slicing** \n",
"**Slicing**\n",
"\n",
"Arrays, like other Python sequences can also be sliced:\n"
]
......@@ -1301,7 +1280,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 102,
"metadata": {
"collapsed": false
},
......@@ -1313,7 +1292,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 1,
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
......
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