|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## What is Jupyter Notebook?\n", |
| 8 | + "- The Jupyter Notebook is an **interactive computing environment** that enables users to author notebook documents that include: - Live code - Interactive widgets - Plots - Narrative text - Equations - Images - Video\n", |
| 9 | + "- Enables code and text combination for user convenient.\n", |
| 10 | + "### Components\n", |
| 11 | + "- **The notebook web application**: An interactive web application for writing and running code interactively and authoring notebook documents.\n", |
| 12 | + "- **Kernels**: Separate processes started by the notebook web application that runs users’ code in a given language and returns output back to the notebook web application.\n", |
| 13 | + "- **Notebook documents**: Self-contained documents that contain a representation of all content visible in the notebook web application, including inputs and outputs of the computations, narrative text, equations, images, and rich media representations of objects.\n", |
| 14 | + "### Notebook\n", |
| 15 | + "Notebook documents contain the only the **input and output** of the interactive session.\n", |
| 16 | + "When you run the notebook web application on your computer, notebook documents are just files on your local filesystem with a **```.ipynb```** extension. This format will serve us when submitting the HWs.\n", |
| 17 | + "These files are JSON files, which are rendered in the web browser" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "# 1. Open notebook dashboard\n", |
| 25 | + "**cmd -> type \"jupyter notebook\"** \n", |
| 26 | + "Open an existing ```.ipynb``` and create a new one \n", |
| 27 | + "File browser" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "markdown", |
| 32 | + "metadata": {}, |
| 33 | + "source": [ |
| 34 | + "# 2. Overview of the Notebook UI\n", |
| 35 | + "Consists of:\n", |
| 36 | + "- Menu (save, Insert cells, Kernel)\n", |
| 37 | + "- Toolbar \n", |
| 38 | + "- Notebook area and cells\n", |
| 39 | + "(It is recommended to try the interactive tour in the \"Help:User Interface Tour\")" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "markdown", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "### Cell types:\n", |
| 47 | + "1. Code cell: Input and output of code that is run in the kernel\n", |
| 48 | + "2. Markdown cells: Narrative text\n", |
| 49 | + "3. Raw cells" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "metadata": {}, |
| 55 | + "source": [ |
| 56 | + "Learn the keyboard shortbuts which you will find very useful, such as: Shift+Enter, a, b ..." |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "# 3. Code cells\n", |
| 64 | + "- Cell menu\n", |
| 65 | + "- Kernel menu" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": null, |
| 71 | + "metadata": { |
| 72 | + "collapsed": false |
| 73 | + }, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "print 'Hello world'" |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "markdown", |
| 81 | + "metadata": {}, |
| 82 | + "source": [ |
| 83 | + "### Assigning variables" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": null, |
| 89 | + "metadata": { |
| 90 | + "collapsed": false |
| 91 | + }, |
| 92 | + "outputs": [], |
| 93 | + "source": [ |
| 94 | + "x = 5 #assignment\n", |
| 95 | + "y = x + 2\n", |
| 96 | + "x==4 #condition" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": null, |
| 102 | + "metadata": { |
| 103 | + "collapsed": false |
| 104 | + }, |
| 105 | + "outputs": [], |
| 106 | + "source": [ |
| 107 | + "x" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "markdown", |
| 112 | + "metadata": {}, |
| 113 | + "source": [ |
| 114 | + "### importing" |
| 115 | + ] |
| 116 | + }, |
| 117 | + { |
| 118 | + "cell_type": "code", |
| 119 | + "execution_count": null, |
| 120 | + "metadata": { |
| 121 | + "collapsed": false |
| 122 | + }, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "import numpy as np" |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": null, |
| 131 | + "metadata": { |
| 132 | + "collapsed": false |
| 133 | + }, |
| 134 | + "outputs": [], |
| 135 | + "source": [ |
| 136 | + "print np.random.random()" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": null, |
| 142 | + "metadata": { |
| 143 | + "collapsed": false |
| 144 | + }, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "#defining a function\n", |
| 148 | + "def fun(v):\n", |
| 149 | + " '''2nd power function'''\n", |
| 150 | + " return np.power(v,2)" |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "code", |
| 155 | + "execution_count": null, |
| 156 | + "metadata": { |
| 157 | + "collapsed": false |
| 158 | + }, |
| 159 | + "outputs": [], |
| 160 | + "source": [ |
| 161 | + "for i in range(10): #for loop\n", |
| 162 | + " print i,fun(i)" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "markdown", |
| 167 | + "metadata": {}, |
| 168 | + "source": [ |
| 169 | + "# 4. Markdown cells\n", |
| 170 | + "- Convert a cell to markdown\n", |
| 171 | + "- All HTML tabs are supported!\n", |
| 172 | + "- Nice tutorials to experience the md language: [md_toturial1](http://commonmark.org/help/tutorial/) [md_toturial2](http://www.markdowntutorial.com/)\n", |
| 173 | + "- And a couple of links about Markdown: [Link to markdown reference](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) [Link to another markdown reference](https://daringfireball.net/projects/markdown/syntax)" |
| 174 | + ] |
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "markdown", |
| 178 | + "metadata": {}, |
| 179 | + "source": [ |
| 180 | + "# This is Heading1\n", |
| 181 | + "## This is Heading2\n", |
| 182 | + "\n", |
| 183 | + "some gray colored text:\n", |
| 184 | + "> This is where we can bring qoutes and present them nicely\n", |
| 185 | + "\n", |
| 186 | + "And this is the paragraph about something very important. Even math:\n", |
| 187 | + "\n", |
| 188 | + "$$y_{sub} = \\sqrt(x_{sub})$$\n", |
| 189 | + "\n", |
| 190 | + "Or python code example:\n", |
| 191 | + "```\n", |
| 192 | + "def foo():\n", |
| 193 | + " return \"foo\"\n", |
| 194 | + "```" |
| 195 | + ] |
| 196 | + }, |
| 197 | + { |
| 198 | + "cell_type": "markdown", |
| 199 | + "metadata": {}, |
| 200 | + "source": [ |
| 201 | + "To write a free-text (Markdown) in Ipython Notebook cell, select the cell and Press<b> M </b>. If the cell is entered (text input) press <b> ESC </b> first, to exit the cell. <br> To enter the cell again press <b> Enter </b><br>\n", |
| 202 | + "To execute the cell, Press <b> Shift+Enter </b>" |
| 203 | + ] |
| 204 | + }, |
| 205 | + { |
| 206 | + "cell_type": "markdown", |
| 207 | + "metadata": {}, |
| 208 | + "source": [ |
| 209 | + "To convert the cell back to code cell, press <b> Y" |
| 210 | + ] |
| 211 | + }, |
| 212 | + { |
| 213 | + "cell_type": "markdown", |
| 214 | + "metadata": {}, |
| 215 | + "source": [ |
| 216 | + "To add new cell press **A** (above) or **B** (beneath) <br>\n", |
| 217 | + "To delete a cell press **DD**" |
| 218 | + ] |
| 219 | + }, |
| 220 | + { |
| 221 | + "cell_type": "markdown", |
| 222 | + "metadata": {}, |
| 223 | + "source": [ |
| 224 | + "# 5. Matplotlib" |
| 225 | + ] |
| 226 | + }, |
| 227 | + { |
| 228 | + "cell_type": "code", |
| 229 | + "execution_count": null, |
| 230 | + "metadata": { |
| 231 | + "collapsed": false |
| 232 | + }, |
| 233 | + "outputs": [], |
| 234 | + "source": [ |
| 235 | + "import matplotlib.pyplot as plt\n", |
| 236 | + "%matplotlib inline" |
| 237 | + ] |
| 238 | + }, |
| 239 | + { |
| 240 | + "cell_type": "code", |
| 241 | + "execution_count": null, |
| 242 | + "metadata": { |
| 243 | + "collapsed": false |
| 244 | + }, |
| 245 | + "outputs": [], |
| 246 | + "source": [ |
| 247 | + "x = np.linspace(0, 100)\n", |
| 248 | + "y = np.sqrt(x)" |
| 249 | + ] |
| 250 | + }, |
| 251 | + { |
| 252 | + "cell_type": "code", |
| 253 | + "execution_count": null, |
| 254 | + "metadata": { |
| 255 | + "collapsed": false |
| 256 | + }, |
| 257 | + "outputs": [], |
| 258 | + "source": [ |
| 259 | + "print x\n", |
| 260 | + "print y" |
| 261 | + ] |
| 262 | + }, |
| 263 | + { |
| 264 | + "cell_type": "code", |
| 265 | + "execution_count": null, |
| 266 | + "metadata": { |
| 267 | + "collapsed": false |
| 268 | + }, |
| 269 | + "outputs": [], |
| 270 | + "source": [ |
| 271 | + "plt.plot(x, y)\n", |
| 272 | + "plt.show()" |
| 273 | + ] |
| 274 | + }, |
| 275 | + { |
| 276 | + "cell_type": "markdown", |
| 277 | + "metadata": {}, |
| 278 | + "source": [ |
| 279 | + "# 6. Extra\n", |
| 280 | + "- Auto-completion using ```tab```\n", |
| 281 | + "- Function documantation using ```Shift+tab```\n", |
| 282 | + "- Download as .py or .ipynb\n", |
| 283 | + "- Restart kernel, Interrupt kernel" |
| 284 | + ] |
| 285 | + }, |
| 286 | + { |
| 287 | + "cell_type": "markdown", |
| 288 | + "metadata": { |
| 289 | + "collapsed": true |
| 290 | + }, |
| 291 | + "source": [ |
| 292 | + "*based heavily on [link](http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/What%20is%20the%20Jupyter%20Notebook.html)* \n", |
| 293 | + "*[Link for downloading Anaconda](https://www.continuum.io/downloads).* **Make sure to download the 2.7 version**" |
| 294 | + ] |
| 295 | + }, |
| 296 | + { |
| 297 | + "cell_type": "markdown", |
| 298 | + "metadata": {}, |
| 299 | + "source": [ |
| 300 | + "## Saving and Exiting" |
| 301 | + ] |
| 302 | + }, |
| 303 | + { |
| 304 | + "cell_type": "markdown", |
| 305 | + "metadata": {}, |
| 306 | + "source": [ |
| 307 | + "Ipython Notebook has AutoSaves. In order to properly save the notebook go to **File-> Save** and then **File->Close and Halt**. You can also export the code to regular Python file (**.py**) or even a pdf using **File-> Download as**" |
| 308 | + ] |
| 309 | + }, |
| 310 | + { |
| 311 | + "cell_type": "code", |
| 312 | + "execution_count": null, |
| 313 | + "metadata": { |
| 314 | + "collapsed": true |
| 315 | + }, |
| 316 | + "outputs": [], |
| 317 | + "source": [] |
| 318 | + } |
| 319 | + ], |
| 320 | + "metadata": { |
| 321 | + "kernelspec": { |
| 322 | + "display_name": "Python 2", |
| 323 | + "language": "python", |
| 324 | + "name": "python2" |
| 325 | + }, |
| 326 | + "language_info": { |
| 327 | + "codemirror_mode": { |
| 328 | + "name": "ipython", |
| 329 | + "version": 2 |
| 330 | + }, |
| 331 | + "file_extension": ".py", |
| 332 | + "mimetype": "text/x-python", |
| 333 | + "name": "python", |
| 334 | + "nbconvert_exporter": "python", |
| 335 | + "pygments_lexer": "ipython2", |
| 336 | + "version": "2.7.10" |
| 337 | + } |
| 338 | + }, |
| 339 | + "nbformat": 4, |
| 340 | + "nbformat_minor": 0 |
| 341 | +} |
0 commit comments