{ "metadata": { "name": "", "signature": "sha256:5a99f5dbfaf0da0575bf4754a64bd8a27fdb365c554148e7e424769fa98f4778" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "O que \u00e9 o IPython?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "IPython \u00e9 um ambiente para computa\u00e7\u00e3o interativa e explorat\u00f3ria.\n", "\n", "* Shell iterativo poderosos(Console, QtBased, WebBased)\n", "* Arquitetura desacoplada com um Kernel que permite conex\u00e3o com m\u00faltiplos clientes \n", "* Arquitetura que permite programa\u00e7\u00e3o paralela interativa\n", "* Multi-linguagem de program\u00e7\u00e3o(Python, Ruby, R, Julia e Haskell)\n", "* Opensource" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "| This | is |\n", "|------|------|\n", "| a | table| \n", "\n", "\n", "A tabela ser\u00e1 renderizada em HTML\n", "\n", "| This | is |\n", "|------|------|\n", "| a | table| " ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Suporte a LaTeX" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "O IPython Notebook usa MathJax para rederizar express\u00f5es matem\u00e1ticas usando LaTeX. Pode ser em linha: \n", "$e^{i\\pi} + 1 = 0$ ou em bloco:\n", "\n", "$$e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i$$" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Elementos ricos com Python" ] }, { "cell_type": "heading", "level": 5, "metadata": {}, "source": [ "Imagens" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import Image" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "Image(url='http://python.org/images/python-logo.gif')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "Image('http://ipython.org/_static/IPy_header.png')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 5, "metadata": {}, "source": [ "V\u00eddeos do Youtube" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import YouTubeVideo\n", "YouTubeVideo('kkwiQmGWK4c')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 5, "metadata": {}, "source": [ "Audio" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import Audio" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "max_time = 3\n", "f1 = 220.0\n", "f2 = 224.0\n", "rate = 44100.0\n", "L = 3\n", "times = np.linspace(0,L,rate*L)\n", "signal = np.sin(2*np.pi*f1*times) + np.sin(2*np.pi*f2*times)\n", "\n", "Audio(data=signal, rate=rate)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "audio_plt = plt.plot(times, signal)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Usando sympy para s\u00edmbolos matem\u00e1ticos" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sympy import *\n", "init_printing()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "x = Symbol('x')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "(pi + x)**2" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "(x+1)*(x+2)*(x+3)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "expand((x+1)*(x+2)*(x+3))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Widgets interativos" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.html.widgets import interact, interactive, fixed" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "def f(x):\n", " print x" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "interact(f, x=10);" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "interact(f, x=True);" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "interact(f, x='Hi there!');" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "@interact(x=True, y=1.0)\n", "def g(x, y):\n", " print(x, y)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Exemplo completo com o scikit-image" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import skimage\n", "from skimage import data, filter, io\n", "\n", "from IPython.display import display" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "i = data.coffee()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "lims = (0.0,1.0,0.01)\n", "\n", "def edit_image(image, sigma=0.1, r=1.0, g=1.0, b=1.0):\n", " new_image = filter.gaussian_filter(image, sigma=sigma, multichannel=True)\n", " new_image[:,:,0] = r*new_image[:,:,0]\n", " new_image[:,:,1] = g*new_image[:,:,1]\n", " new_image[:,:,2] = b*new_image[:,:,2]\n", " new_image = io.Image(new_image)\n", " display(new_image)\n", " return new_image\n", "\n", "w = interactive(edit_image, image=fixed(i), sigma=(0.0,10.0,0.1), r=lims, g=lims, b=lims)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "display(w)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Integra\u00e7\u00e3o com Pandas para manipula\u00e7\u00e3o de dados" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import pandas as pd" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "ts = pd.Series(np.random.randn(10), index=pd.date_range('1/1/2014', periods=10))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pd.DataFrame(np.random.randn(10, 4), index=ts.index,\n", " columns=['A', 'B', 'C', 'D'])\n", " \n", "df = df.cumsum()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "df" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "plt.figure()\n", "df.plot()\n", "plt.legend(loc='best')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Disponiblizando seus notebooks no nbviewer" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import IFrame" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "IFrame('http://nbviewer.ipython.org/', 800, 600)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Refer\u00eancia" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Esse tutorial \u00e9 completamente baseado no [v\u00eddeo do Fernando Perez](https://www.youtube.com/watch?v=XFw1JVXKJss)\n", "* http://www.scipy.org/\n", "* http://ipython.org" ] } ], "metadata": {} } ] }