{ "metadata": { "name": "Python Basics" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Interactive Python" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"hello\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "hello\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "4 + 5" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 2, "text": [ "9" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "3.5 + 'e'" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "unsupported operand type(s) for +: 'float' and 'str'", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m3.5\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'e'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'float' and 'str'" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Built-in data types" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Lists" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [1,2,3,4,5]\n", "a[0]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 4, "text": [ "1" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "a[0] + a[1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 5, "text": [ "3" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "range(5)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 6, "text": [ "[0, 1, 2, 3, 4]" ] } ], "prompt_number": 6 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Iterating over lists" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [0, 1]\n", "for i in range(20):\n", " a += [ a[-1] + a[-2] ]\n", "\n", "print a " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]\n" ] } ], "prompt_number": 7 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "List comprehensions" ] }, { "cell_type": "code", "collapsed": false, "input": [ "range(20)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 9, "text": [ "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "[a[i+1]/a[i+2] for i in range(20)]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 8, "text": [ "[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "[a[i+1]/float(a[i+2]) for i in range(20)]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 10, "text": [ "[1.0,\n", " 0.5,\n", " 0.6666666666666666,\n", " 0.6,\n", " 0.625,\n", " 0.6153846153846154,\n", " 0.6190476190476191,\n", " 0.6176470588235294,\n", " 0.6181818181818182,\n", " 0.6179775280898876,\n", " 0.6180555555555556,\n", " 0.6180257510729614,\n", " 0.6180371352785146,\n", " 0.6180327868852459,\n", " 0.6180344478216818,\n", " 0.6180338134001252,\n", " 0.6180340557275542,\n", " 0.6180339631667066,\n", " 0.6180339985218034,\n", " 0.618033985017358]" ] } ], "prompt_number": 10 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Other list functions" ] }, { "cell_type": "code", "collapsed": false, "input": [ "0 in a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 11, "text": [ "True" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "0.5 in a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 12, "text": [ "False" ] } ], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "b = [a, 2, 3] * 3" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "b" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 14, "text": [ "[[0,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3,\n", " [0,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3,\n", " [0,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3]" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "a[0] = 1\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 17, "text": [ "[1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946]" ] } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [ "b" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 18, "text": [ "[[1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3,\n", " [1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3,\n", " [1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946],\n", " 2,\n", " 3]" ] } ], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "len(a)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 19, "text": [ "22" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "max(a), min(a)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 20, "text": [ "(10946, 1)" ] } ], "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ "type(a), type(a[0])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 22, "text": [ "(list, int)" ] } ], "prompt_number": 22 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "List object functions" ] }, { "cell_type": "code", "collapsed": true, "input": [ "dir(a)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 23, "text": [ "['__add__',\n", " '__class__',\n", " '__contains__',\n", " '__delattr__',\n", " '__delitem__',\n", " '__delslice__',\n", " '__doc__',\n", " '__eq__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getitem__',\n", " '__getslice__',\n", " '__gt__',\n", " '__hash__',\n", " '__iadd__',\n", " '__imul__',\n", " '__init__',\n", " '__iter__',\n", " '__le__',\n", " '__len__',\n", " '__lt__',\n", " '__mul__',\n", " '__ne__',\n", " '__new__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__reversed__',\n", " '__rmul__',\n", " '__setattr__',\n", " '__setitem__',\n", " '__setslice__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__',\n", " 'append',\n", " 'count',\n", " 'extend',\n", " 'index',\n", " 'insert',\n", " 'pop',\n", " 'remove',\n", " 'reverse',\n", " 'sort']" ] } ], "prompt_number": 23 }, { "cell_type": "code", "collapsed": false, "input": [ "a.append(3)\n", "a[-1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 24, "text": [ "3" ] } ], "prompt_number": 24 }, { "cell_type": "code", "collapsed": false, "input": [ "def func(e):\n", " return e\n", "\n", "a.append(func)\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 26, "text": [ "[1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946,\n", " 3,\n", " ]" ] } ], "prompt_number": 26 }, { "cell_type": "code", "collapsed": false, "input": [ "a[-1](10), a[-1]('hello')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 28, "text": [ "(10, 'hello')" ] } ], "prompt_number": 28 }, { "cell_type": "code", "collapsed": false, "input": [ "a.count(1)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 29, "text": [ "3" ] } ], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "a.reverse()\n", "a[2:]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 46, "text": [ "[6765,\n", " 4181,\n", " 2584,\n", " 1597,\n", " 987,\n", " 610,\n", " 377,\n", " 233,\n", " 144,\n", " 89,\n", " 55,\n", " 34,\n", " 21,\n", " 13,\n", " 8,\n", " 5,\n", " 3,\n", " 3,\n", " 2,\n", " 1,\n", " 1,\n", " 1]" ] } ], "prompt_number": 46 }, { "cell_type": "code", "collapsed": false, "input": [ "a.sort()\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 47, "text": [ "[1,\n", " 1,\n", " 1,\n", " 2,\n", " 3,\n", " 3,\n", " 5,\n", " 8,\n", " 13,\n", " 21,\n", " 34,\n", " 55,\n", " 89,\n", " 144,\n", " 233,\n", " 377,\n", " 610,\n", " 987,\n", " 1597,\n", " 2584,\n", " 4181,\n", " 6765,\n", " 10946,\n", " ]" ] } ], "prompt_number": 47 }, { "cell_type": "code", "collapsed": false, "input": [ "a.index(3)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 48, "text": [ "4" ] } ], "prompt_number": 48 }, { "cell_type": "code", "collapsed": false, "input": [ "a.count(3)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 49, "text": [ "2" ] } ], "prompt_number": 49 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Slicing" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a[2:-5]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 50, "text": [ "[1, 2, 3, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]" ] } ], "prompt_number": 50 }, { "cell_type": "code", "collapsed": false, "input": [ "a[2::2] # Third number in slice is element jump (useful for deinterleaving!)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 51, "text": [ "[1, 3, 5, 13, 34, 89, 233, 610, 1597, 4181, 10946]" ] } ], "prompt_number": 51 }, { "cell_type": "markdown", "metadata": {}, "source": [ "More: http://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange\n" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Strings" ] }, { "cell_type": "code", "collapsed": false, "input": [ "name = 'andres'\n", "surname = \"cabrera\"\n", "name + ' ' + surname" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 52, "text": [ "'andres cabrera'" ] } ], "prompt_number": 52 }, { "cell_type": "code", "collapsed": false, "input": [ "_.capitalize()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 53, "text": [ "'Andres cabrera'" ] } ], "prompt_number": 53 }, { "cell_type": "code", "collapsed": false, "input": [ "__.title()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 54, "text": [ "'Andres Cabrera'" ] } ], "prompt_number": 54 }, { "cell_type": "code", "collapsed": false, "input": [ "___.upper()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 55, "text": [ "'ANDRES CABRERA'" ] } ], "prompt_number": 55 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname = __" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 56 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname.count('A'), fullname.isalpha(), fullname.startswith('A')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 57, "text": [ "(1, False, True)" ] } ], "prompt_number": 57 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname.title().split()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 61, "text": [ "['Andres', 'Cabrera']" ] } ], "prompt_number": 61 }, { "cell_type": "code", "collapsed": false, "input": [ "' '.join([name, surname])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 62, "text": [ "'andres cabrera'" ] } ], "prompt_number": 62 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname.replace('A', 'a')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 63, "text": [ "'andres Cabrera'" ] } ], "prompt_number": 63 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 64, "text": [ "'Andres Cabrera'" ] } ], "prompt_number": 64 }, { "cell_type": "code", "collapsed": false, "input": [ "fullname = (\"%s %s\"%(name, surname)).title()\n", "print fullname" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Andres Cabrera\n" ] } ], "prompt_number": 65 }, { "cell_type": "code", "collapsed": false, "input": [ "'90'.zfill(4)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 66, "text": [ "'0090'" ] } ], "prompt_number": 66 }, { "cell_type": "code", "collapsed": false, "input": [ "'90'.center(4)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 67, "text": [ "' 90 '" ] } ], "prompt_number": 67 }, { "cell_type": "markdown", "metadata": {}, "source": [ "More info: http://docs.python.org/2/library/stdtypes.html#string-methods\n" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Boolean" ] }, { "cell_type": "code", "collapsed": false, "input": [ "(1 + 1) == 3" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 68, "text": [ "False" ] } ], "prompt_number": 68 }, { "cell_type": "code", "collapsed": false, "input": [ "e = 3 == 4" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 69 }, { "cell_type": "code", "collapsed": false, "input": [ "not e" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 70, "text": [ "True" ] } ], "prompt_number": 70 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Dictionaries" ] }, { "cell_type": "code", "collapsed": false, "input": [ "d = {'name': 'andres', 'surname': 'cabrera'}\n", "fullname = \"%s %s\"%(d['name'], d['surname'])\n", "fullname.title()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 71, "text": [ "'Andres Cabrera'" ] } ], "prompt_number": 71 }, { "cell_type": "code", "collapsed": false, "input": [ "d = { 1: 'hello'}" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 73 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Indentation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Scope is defined by indentation, not special characters!" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Functions" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def myadd(first, second):\n", " return first + second" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 74 }, { "cell_type": "code", "collapsed": false, "input": [ "myadd(3,4)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 75, "text": [ "7" ] } ], "prompt_number": 75 }, { "cell_type": "code", "collapsed": false, "input": [ "myadd('a', 'b')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 76, "text": [ "'ab'" ] } ], "prompt_number": 76 }, { "cell_type": "code", "collapsed": false, "input": [ "myadd(3, 'a')" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "unsupported operand type(s) for +: 'int' and 'str'", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmyadd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'a'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m\u001b[0m in \u001b[0;36mmyadd\u001b[0;34m(first, second)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmyadd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfirst\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msecond\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfirst\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0msecond\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" ] } ], "prompt_number": 77 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Iteration and loops" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [0, 1]\n", "for i in range(20):\n", " a += [ a[-1] + a[-2] ]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 78 }, { "cell_type": "code", "collapsed": false, "input": [ "a = [0, 1]\n", "while a[-1] < 1000:\n", " a.append(a[-1] + a[-2])\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 79, "text": [ "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]" ] } ], "prompt_number": 79 }, { "cell_type": "code", "collapsed": false, "input": [ "d = {'name': 'andres', 'surname': 'cabrera'}\n", "for key in d:\n", " print \"%s:%s\"%(key, d[key])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "surname:cabrera\n", "name:andres\n" ] } ], "prompt_number": 80 }, { "cell_type": "code", "collapsed": false, "input": [ "for char in name:\n", " print char," ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "a n d r e s\n" ] } ], "prompt_number": 84 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Help in Ipython" ] }, { "cell_type": "code", "collapsed": false, "input": [ "str?" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 85 }, { "cell_type": "code", "collapsed": false, "input": [ "name.center?" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 86 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or use the tab key to display pop-up help (in notebook only)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "help(str)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Help on class str in module __builtin__:\n", "\n", "class str(basestring)\n", " | str(object='') -> string\n", " | \n", " | Return a nice string representation of the object.\n", " | If the argument is a string, the return value is the same object.\n", " | \n", " | Method resolution order:\n", " | str\n", " | basestring\n", " | object\n", " | \n", " | Methods defined here:\n", " | \n", " | __add__(...)\n", " | x.__add__(y) <==> x+y\n", " | \n", " | __contains__(...)\n", " | x.__contains__(y) <==> y in x\n", " | \n", " | __eq__(...)\n", " | x.__eq__(y) <==> x==y\n", " | \n", " | __format__(...)\n", " | S.__format__(format_spec) -> string\n", " | \n", " | Return a formatted version of S as described by format_spec.\n", " | \n", " | __ge__(...)\n", " | x.__ge__(y) <==> x>=y\n", " | \n", " | __getattribute__(...)\n", " | x.__getattribute__('name') <==> x.name\n", " | \n", " | __getitem__(...)\n", " | x.__getitem__(y) <==> x[y]\n", " | \n", " | __getnewargs__(...)\n", " | \n", " | __getslice__(...)\n", " | x.__getslice__(i, j) <==> x[i:j]\n", " | \n", " | Use of negative indices is not supported.\n", " | \n", " | __gt__(...)\n", " | x.__gt__(y) <==> x>y\n", " | \n", " | __hash__(...)\n", " | x.__hash__() <==> hash(x)\n", " | \n", " | __le__(...)\n", " | x.__le__(y) <==> x<=y\n", " | \n", " | __len__(...)\n", " | x.__len__() <==> len(x)\n", " | \n", " | __lt__(...)\n", " | x.__lt__(y) <==> x x%y\n", " | \n", " | __mul__(...)\n", " | x.__mul__(n) <==> x*n\n", " | \n", " | __ne__(...)\n", " | x.__ne__(y) <==> x!=y\n", " | \n", " | __repr__(...)\n", " | x.__repr__() <==> repr(x)\n", " | \n", " | __rmod__(...)\n", " | x.__rmod__(y) <==> y%x\n", " | \n", " | __rmul__(...)\n", " | x.__rmul__(n) <==> n*x\n", " | \n", " | __sizeof__(...)\n", " | S.__sizeof__() -> size of S in memory, in bytes\n", " | \n", " | __str__(...)\n", " | x.__str__() <==> str(x)\n", " | \n", " | capitalize(...)\n", " | S.capitalize() -> string\n", " | \n", " | Return a copy of the string S with only its first character\n", " | capitalized.\n", " | \n", " | center(...)\n", " | S.center(width[, fillchar]) -> string\n", " | \n", " | Return S centered in a string of length width. Padding is\n", " | done using the specified fill character (default is a space)\n", " | \n", " | count(...)\n", " | S.count(sub[, start[, end]]) -> int\n", " | \n", " | Return the number of non-overlapping occurrences of substring sub in\n", " | string S[start:end]. Optional arguments start and end are interpreted\n", " | as in slice notation.\n", " | \n", " | decode(...)\n", " | S.decode([encoding[,errors]]) -> object\n", " | \n", " | Decodes S using the codec registered for encoding. encoding defaults\n", " | to the default encoding. errors may be given to set a different error\n", " | handling scheme. Default is 'strict' meaning that encoding errors raise\n", " | a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n", " | as well as any other name registered with codecs.register_error that is\n", " | able to handle UnicodeDecodeErrors.\n", " | \n", " | encode(...)\n", " | S.encode([encoding[,errors]]) -> object\n", " | \n", " | Encodes S using the codec registered for encoding. encoding defaults\n", " | to the default encoding. errors may be given to set a different error\n", " | handling scheme. Default is 'strict' meaning that encoding errors raise\n", " | a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n", " | 'xmlcharrefreplace' as well as any other name registered with\n", " | codecs.register_error that is able to handle UnicodeEncodeErrors.\n", " | \n", " | endswith(...)\n", " | S.endswith(suffix[, start[, end]]) -> bool\n", " | \n", " | Return True if S ends with the specified suffix, False otherwise.\n", " | With optional start, test S beginning at that position.\n", " | With optional end, stop comparing S at that position.\n", " | suffix can also be a tuple of strings to try.\n", " | \n", " | expandtabs(...)\n", " | S.expandtabs([tabsize]) -> string\n", " | \n", " | Return a copy of S where all tab characters are expanded using spaces.\n", " | If tabsize is not given, a tab size of 8 characters is assumed.\n", " | \n", " | find(...)\n", " | S.find(sub [,start [,end]]) -> int\n", " | \n", " | Return the lowest index in S where substring sub is found,\n", " | such that sub is contained within S[start:end]. Optional\n", " | arguments start and end are interpreted as in slice notation.\n", " | \n", " | Return -1 on failure.\n", " | \n", " | format(...)\n", " | S.format(*args, **kwargs) -> string\n", " | \n", " | Return a formatted version of S, using substitutions from args and kwargs.\n", " | The substitutions are identified by braces ('{' and '}').\n", " | \n", " | index(...)\n", " | S.index(sub [,start [,end]]) -> int\n", " | \n", " | Like S.find() but raise ValueError when the substring is not found.\n", " | \n", " | isalnum(...)\n", " | S.isalnum() -> bool\n", " | \n", " | Return True if all characters in S are alphanumeric\n", " | and there is at least one character in S, False otherwise.\n", " | \n", " | isalpha(...)\n", " | S.isalpha() -> bool\n", " | \n", " | Return True if all characters in S are alphabetic\n", " | and there is at least one character in S, False otherwise.\n", " | \n", " | isdigit(...)\n", " | S.isdigit() -> bool\n", " | \n", " | Return True if all characters in S are digits\n", " | and there is at least one character in S, False otherwise.\n", " | \n", " | islower(...)\n", " | S.islower() -> bool\n", " | \n", " | Return True if all cased characters in S are lowercase and there is\n", " | at least one cased character in S, False otherwise.\n", " | \n", " | isspace(...)\n", " | S.isspace() -> bool\n", " | \n", " | Return True if all characters in S are whitespace\n", " | and there is at least one character in S, False otherwise.\n", " | \n", " | istitle(...)\n", " | S.istitle() -> bool\n", " | \n", " | Return True if S is a titlecased string and there is at least one\n", " | character in S, i.e. uppercase characters may only follow uncased\n", " | characters and lowercase characters only cased ones. Return False\n", " | otherwise.\n", " | \n", " | isupper(...)\n", " | S.isupper() -> bool\n", " | \n", " | Return True if all cased characters in S are uppercase and there is\n", " | at least one cased character in S, False otherwise.\n", " | \n", " | join(...)\n", " | S.join(iterable) -> string\n", " | \n", " | Return a string which is the concatenation of the strings in the\n", " | iterable. The separator between elements is S.\n", " | \n", " | ljust(...)\n", " | S.ljust(width[, fillchar]) -> string\n", " | \n", " | Return S left-justified in a string of length width. Padding is\n", " | done using the specified fill character (default is a space).\n", " | \n", " | lower(...)\n", " | S.lower() -> string\n", " | \n", " | Return a copy of the string S converted to lowercase.\n", " | \n", " | lstrip(...)\n", " | S.lstrip([chars]) -> string or unicode\n", " | \n", " | Return a copy of the string S with leading whitespace removed.\n", " | If chars is given and not None, remove characters in chars instead.\n", " | If chars is unicode, S will be converted to unicode before stripping\n", " | \n", " | partition(...)\n", " | S.partition(sep) -> (head, sep, tail)\n", " | \n", " | Search for the separator sep in S, and return the part before it,\n", " | the separator itself, and the part after it. If the separator is not\n", " | found, return S and two empty strings.\n", " | \n", " | replace(...)\n", " | S.replace(old, new[, count]) -> string\n", " | \n", " | Return a copy of string S with all occurrences of substring\n", " | old replaced by new. If the optional argument count is\n", " | given, only the first count occurrences are replaced.\n", " | \n", " | rfind(...)\n", " | S.rfind(sub [,start [,end]]) -> int\n", " | \n", " | Return the highest index in S where substring sub is found,\n", " | such that sub is contained within S[start:end]. Optional\n", " | arguments start and end are interpreted as in slice notation.\n", " | \n", " | Return -1 on failure.\n", " | \n", " | rindex(...)\n", " | S.rindex(sub [,start [,end]]) -> int\n", " | \n", " | Like S.rfind() but raise ValueError when the substring is not found.\n", " | \n", " | rjust(...)\n", " | S.rjust(width[, fillchar]) -> string\n", " | \n", " | Return S right-justified in a string of length width. Padding is\n", " | done using the specified fill character (default is a space)\n", " | \n", " | rpartition(...)\n", " | S.rpartition(sep) -> (head, sep, tail)\n", " | \n", " | Search for the separator sep in S, starting at the end of S, and return\n", " | the part before it, the separator itself, and the part after it. If the\n", " | separator is not found, return two empty strings and S.\n", " | \n", " | rsplit(...)\n", " | S.rsplit([sep [,maxsplit]]) -> list of strings\n", " | \n", " | Return a list of the words in the string S, using sep as the\n", " | delimiter string, starting at the end of the string and working\n", " | to the front. If maxsplit is given, at most maxsplit splits are\n", " | done. If sep is not specified or is None, any whitespace string\n", " | is a separator.\n", " | \n", " | rstrip(...)\n", " | S.rstrip([chars]) -> string or unicode\n", " | \n", " | Return a copy of the string S with trailing whitespace removed.\n", " | If chars is given and not None, remove characters in chars instead.\n", " | If chars is unicode, S will be converted to unicode before stripping\n", " | \n", " | split(...)\n", " | S.split([sep [,maxsplit]]) -> list of strings\n", " | \n", " | Return a list of the words in the string S, using sep as the\n", " | delimiter string. If maxsplit is given, at most maxsplit\n", " | splits are done. If sep is not specified or is None, any\n", " | whitespace string is a separator and empty strings are removed\n", " | from the result.\n", " | \n", " | splitlines(...)\n", " | S.splitlines(keepends=False) -> list of strings\n", " | \n", " | Return a list of the lines in S, breaking at line boundaries.\n", " | Line breaks are not included in the resulting list unless keepends\n", " | is given and true.\n", " | \n", " | startswith(...)\n", " | S.startswith(prefix[, start[, end]]) -> bool\n", " | \n", " | Return True if S starts with the specified prefix, False otherwise.\n", " | With optional start, test S beginning at that position.\n", " | With optional end, stop comparing S at that position.\n", " | prefix can also be a tuple of strings to try.\n", " | \n", " | strip(...)\n", " | S.strip([chars]) -> string or unicode\n", " | \n", " | Return a copy of the string S with leading and trailing\n", " | whitespace removed.\n", " | If chars is given and not None, remove characters in chars instead.\n", " | If chars is unicode, S will be converted to unicode before stripping\n", " | \n", " | swapcase(...)\n", " | S.swapcase() -> string\n", " | \n", " | Return a copy of the string S with uppercase characters\n", " | converted to lowercase and vice versa.\n", " | \n", " | title(...)\n", " | S.title() -> string\n", " | \n", " | Return a titlecased version of S, i.e. words start with uppercase\n", " | characters, all remaining cased characters have lowercase.\n", " | \n", " | translate(...)\n", " | S.translate(table [,deletechars]) -> string\n", " | \n", " | Return a copy of the string S, where all characters occurring\n", " | in the optional argument deletechars are removed, and the\n", " | remaining characters have been mapped through the given\n", " | translation table, which must be a string of length 256 or None.\n", " | If the table argument is None, no translation is applied and\n", " | the operation simply removes the characters in deletechars.\n", " | \n", " | upper(...)\n", " | S.upper() -> string\n", " | \n", " | Return a copy of the string S converted to uppercase.\n", " | \n", " | zfill(...)\n", " | S.zfill(width) -> string\n", " | \n", " | Pad a numeric string S with zeros on the left, to fill a field\n", " | of the specified width. The string S is never truncated.\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data and other attributes defined here:\n", " | \n", " | __new__ = \n", " | T.__new__(S, ...) -> a new object with type S, a subtype of T\n", "\n" ] } ], "prompt_number": 87 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Modules and namespaces" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import glob" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 88 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Python Standard Library: http://docs.python.org/3/library/\n", "\n", "Documentation for the glob module: http://docs.python.org/3/library/glob.html" ] }, { "cell_type": "code", "collapsed": false, "input": [ "glob.glob(\"*\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 89, "text": [ "['passport.wav',\n", " 'wtk1-prelude1.mid',\n", " 'Graphing with pylab.ipynb',\n", " 'Python Basics.ipynb',\n", " 'Audio FIle IO.ipynb',\n", " 'Symbolic MIR Using Music21.ipynb']" ] } ], "prompt_number": 89 }, { "cell_type": "code", "collapsed": false, "input": [ "glob.glob(\"/home/andres/Music/*\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 90, "text": [ "['/home/andres/Music/Jose Vicente Asuar',\n", " '/home/andres/Music/Ambisonics',\n", " '/home/andres/Music/Unknown Artist']" ] } ], "prompt_number": 90 }, { "cell_type": "code", "collapsed": false, "input": [ "glob.glob(\"/home/andres/Music/*/*/*\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 91, "text": [ "['/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/05. Catedral.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/02. Preludio La Noche.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/08. La Noche II.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/07. Caleidoscopio.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/03. Serenata para mi voz y sonidos sinusoidales.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/06. Divertimento.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/01. Variaciones espctrales (1959).flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/04. Estudio Aleatorio.flac',\n", " '/home/andres/Music/Ambisonics/Brahma/05-Music_W-110425_0127.wav',\n", " '/home/andres/Music/Ambisonics/Brahma/03-Birds_Y-110425_0119.wav',\n", " '/home/andres/Music/Ambisonics/Brahma/07-Music_Y-110425_0127.wav',\n", " '/home/andres/Music/Ambisonics/Brahma/06-Music_X-110425_0127.wav',\n", " '/home/andres/Music/Ambisonics/Brahma/08-Music_Z-110425_0127.wav',\n", " '/home/andres/Music/Ambisonics/Brahma/04-Birds_Z-110425_0119.wav',\n", " '/home/andres/Music/Ambisonics/Ambisonia/NJNight.amb',\n", " '/home/andres/Music/Ambisonics/Ambisonia/PWH_Purcell-Your_hay_it_is_mowed.amb',\n", " '/home/andres/Music/Ambisonics/Ambisonia/Handel-Zadok.amb',\n", " '/home/andres/Music/Ambisonics/Ambisonia/AF_Orfeo_Barocco_REC2.amb',\n", " '/home/andres/Music/Ambisonics/Ambisonia/dc_variations_himmelreich.amb',\n", " '/home/andres/Music/Ambisonics/Ambisonia/cv_Badlands_Day_Insects.amb',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/30. Track 30.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/29. Track 29.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/06. Track 6.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/24. Track 24.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/01. Track 1.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/10. Track 10.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/15. Track 15.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/28. Track 28.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/17. Track 17.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/19. Track 19.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/12. Track 12.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/09. Track 9.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/20. Track 20.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/21. Track 21.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/22. Track 22.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/04. Track 4.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/02. Track 2.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/11. Track 11.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/13. Track 13.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/23. Track 23.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/27. Track 27.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/18. Track 18.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/05. Track 5.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/07. Track 7.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/List.jpg',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/26. Track 26.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/03. Track 3.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/16. Track 16.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/08. Track 8.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/25. Track 25.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/14. Track 14.flac']" ] } ], "prompt_number": 91 }, { "cell_type": "code", "collapsed": false, "input": [ "glob.glob(\"/home/andres/Music/*/*/*.flac\")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 93, "text": [ "['/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/05. Catedral.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/02. Preludio La Noche.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/08. La Noche II.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/07. Caleidoscopio.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/03. Serenata para mi voz y sonidos sinusoidales.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/06. Divertimento.flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/01. Variaciones espctrales (1959).flac',\n", " '/home/andres/Music/Jose Vicente Asuar/Obra Electroacustica I/04. Estudio Aleatorio.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/30. Track 30.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/29. Track 29.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/06. Track 6.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/24. Track 24.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/01. Track 1.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/10. Track 10.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/15. Track 15.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/28. Track 28.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/17. Track 17.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/19. Track 19.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/12. Track 12.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/09. Track 9.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/20. Track 20.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/21. Track 21.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/22. Track 22.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/04. Track 4.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/02. Track 2.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/11. Track 11.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/13. Track 13.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/23. Track 23.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/27. Track 27.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/18. Track 18.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/05. Track 5.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/07. Track 7.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/26. Track 26.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/03. Track 3.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/16. Track 16.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/08. Track 8.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/25. Track 25.flac',\n", " '/home/andres/Music/Unknown Artist/Taxonomy of synthesis techniques (Roads)/14. Track 14.flac']" ] } ], "prompt_number": 93 }, { "cell_type": "code", "collapsed": false, "input": [ "from random import random\n", "random()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 94, "text": [ "0.13353914828109292" ] } ], "prompt_number": 94 }, { "cell_type": "code", "collapsed": false, "input": [ "from os import chdir" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 95 }, { "cell_type": "code", "collapsed": false, "input": [ "chdir(\"/home/andres/Music\")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 96 }, { "cell_type": "code", "collapsed": false, "input": [ "from os import *\n", "listdir('.')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 107, "text": [ "['Jose Vicente Asuar', 'Ambisonics', 'Unknown Artist']" ] } ], "prompt_number": 107 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Importing whole modules into the global namespace is not generally recommended although it can be very convenient" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Files" ] }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('/home/andres/Desktop/IO_Test.csd', 'r')" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "an integer is required", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/home/andres/Desktop/IO_Test.csd'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: an integer is required" ] } ], "prompt_number": 103 }, { "cell_type": "code", "collapsed": false, "input": [ "open" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 108, "text": [ "" ] } ], "prompt_number": 108 }, { "cell_type": "code", "collapsed": false, "input": [ "help(open)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Help on built-in function open in module posix:\n", "\n", "open(...)\n", " open(filename, flag [, mode=0777]) -> fd\n", " \n", " Open a file (for low level IO).\n", "\n" ] } ], "prompt_number": 109 }, { "cell_type": "code", "collapsed": false, "input": [ "del open # yes! Importing a whole module to the global namespace can be bad!!" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 110 }, { "cell_type": "code", "collapsed": false, "input": [ "open" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 111, "text": [ "" ] } ], "prompt_number": 111 }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('/home/andres/Desktop/IO_Test.csd', 'r')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 112 }, { "cell_type": "code", "collapsed": false, "input": [ "lines = f.readlines()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 113 }, { "cell_type": "code", "collapsed": false, "input": [ "lines[:10]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 114, "text": [ "['\\n',\n", " '\\n',\n", " '\\n',\n", " '\\n',\n", " '\\n',\n", " 'sr = 48000\\n',\n", " 'ksmps = 128\\n',\n", " 'nchnls = 2\\n',\n", " '0dbfs = 1\\n',\n", " '\\n']" ] } ], "prompt_number": 114 }, { "cell_type": "code", "collapsed": false, "input": [ "f.close()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 115 }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('/home/andres/Desktop/test.txt','w')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 116 }, { "cell_type": "code", "collapsed": false, "input": [ "f.write(fullname)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 117 }, { "cell_type": "code", "collapsed": false, "input": [ "f.close()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 118 }, { "cell_type": "code", "collapsed": false, "input": [ "f = open('/home/andres/Desktop/test.txt', 'r')\n", "f.read()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 119, "text": [ "'andres cabrera'" ] } ], "prompt_number": 119 }, { "cell_type": "markdown", "metadata": {}, "source": [ "More: http://docs.python.org/2/library/functions.html#open " ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Numpy arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you have run ipython with the *--pylab* option, many numpy and scipy modules and functions are already available.\n", "\n", "You can active this with the ipython \"magic\" command:\n", "\n", " %pylab\n", "\n", "Otherwise, on a regular Python shell, use:\n", "\n", " import numpy as np\n", " from pylab import *\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "linspace(0, 1, 10)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 120, "text": [ "array([ 0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,\n", " 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])" ] } ], "prompt_number": 120 }, { "cell_type": "code", "collapsed": false, "input": [ "linspace(0,1, 10, endpoint=False)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 121, "text": [ "array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])" ] } ], "prompt_number": 121 }, { "cell_type": "code", "collapsed": false, "input": [ "ones(10)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 122, "text": [ "array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" ] } ], "prompt_number": 122 }, { "cell_type": "code", "collapsed": false, "input": [ "ones([2,2])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 123, "text": [ "array([[ 1., 1.],\n", " [ 1., 1.]])" ] } ], "prompt_number": 123 }, { "cell_type": "code", "collapsed": false, "input": [ "arange(10)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 124, "text": [ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" ] } ], "prompt_number": 124 }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also create arrays from a \"generator\" function:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def f(x,y):\n", " return 10 * x + y\n", "\n", "fromfunction(f, (5, 4), dtype= int)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 125, "text": [ "array([[ 0, 1, 2, 3],\n", " [10, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]])" ] } ], "prompt_number": 125 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Array operations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "arr = fromfunction(f, (5, 4), dtype= int)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 126 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Scalar operations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "arr * 2" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 127, "text": [ "array([[ 0, 2, 4, 6],\n", " [20, 22, 24, 26],\n", " [40, 42, 44, 46],\n", " [60, 62, 64, 66],\n", " [80, 82, 84, 86]])" ] } ], "prompt_number": 127 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Matrix operations" ] }, { "cell_type": "code", "collapsed": false, "input": [ "arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 129, "text": [ "array([[ 0, 1, 2, 3],\n", " [10, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]])" ] } ], "prompt_number": 129 }, { "cell_type": "code", "collapsed": false, "input": [ "arr * [3,4,5,6]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 131, "text": [ "array([[ 0, 4, 10, 18],\n", " [ 30, 44, 60, 78],\n", " [ 60, 84, 110, 138],\n", " [ 90, 124, 160, 198],\n", " [120, 164, 210, 258]])" ] } ], "prompt_number": 131 }, { "cell_type": "code", "collapsed": false, "input": [ "dot(arr, [3,4,5,6])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 134, "text": [ "array([ 32, 212, 392, 572, 752])" ] } ], "prompt_number": 134 }, { "cell_type": "code", "collapsed": false, "input": [ "dot(arr, arr.T)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 135, "text": [ "array([[ 14, 74, 134, 194, 254],\n", " [ 74, 534, 994, 1454, 1914],\n", " [ 134, 994, 1854, 2714, 3574],\n", " [ 194, 1454, 2714, 3974, 5234],\n", " [ 254, 1914, 3574, 5234, 6894]])" ] } ], "prompt_number": 135 }, { "cell_type": "code", "collapsed": false, "input": [ "c_[arr, [2,3,4,5,6]]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 140, "text": [ "array([[11, 1, 2, 3, 2],\n", " [10, 11, 12, 13, 3],\n", " [20, 21, 22, 23, 4],\n", " [30, 31, 32, 33, 5],\n", " [40, 41, 42, 43, 6]])" ] } ], "prompt_number": 140 }, { "cell_type": "code", "collapsed": false, "input": [ "r_[arr, arr*2]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 137, "text": [ "array([[ 0, 1, 2, 3],\n", " [10, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43],\n", " [ 0, 2, 4, 6],\n", " [20, 22, 24, 26],\n", " [40, 42, 44, 46],\n", " [60, 62, 64, 66],\n", " [80, 82, 84, 86]])" ] } ], "prompt_number": 137 }, { "cell_type": "code", "collapsed": false, "input": [ "r_[arr, [2,3,4,5]]" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "all the input arrays must have same number of dimensions", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mr_\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.pyc\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[0mobjs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mobjs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfinal_dtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 322\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 323\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_nx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobjs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 324\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_retval\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mValueError\u001b[0m: all the input arrays must have same number of dimensions" ] } ], "prompt_number": 145 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python lists are interpreted as column vectors!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "np.array([2,3,4,5,6])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 146, "text": [ "array([2, 3, 4, 5, 6])" ] } ], "prompt_number": 146 }, { "cell_type": "code", "collapsed": false, "input": [ "r_[arr, np.array([2,3,4,5,6])]" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "all the input arrays must have same number of dimensions", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mr_\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.pyc\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[0mobjs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mobjs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfinal_dtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 322\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 323\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_nx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobjs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 324\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_retval\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mValueError\u001b[0m: all the input arrays must have same number of dimensions" ] } ], "prompt_number": 147 }, { "cell_type": "markdown", "metadata": {}, "source": [ "And so are 1D arrays!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "np.array([2,3,4,5,6], ndmin = 2)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 148, "text": [ "array([[2, 3, 4, 5, 6]])" ] } ], "prompt_number": 148 }, { "cell_type": "code", "collapsed": false, "input": [ "np.array([2,3,4,5,6], ndmin = 2).T" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 149, "text": [ "array([[2],\n", " [3],\n", " [4],\n", " [5],\n", " [6]])" ] } ], "prompt_number": 149 }, { "cell_type": "code", "collapsed": false, "input": [ "r_[arr, np.array([2,3,4,5], ndmin = 2)]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 150, "text": [ "array([[11, 1, 2, 3],\n", " [10, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43],\n", " [ 2, 3, 4, 5]])" ] } ], "prompt_number": 150 }, { "cell_type": "markdown", "metadata": {}, "source": [ "But a 2D array with a single line is a row!" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Array properties" ] }, { "cell_type": "code", "collapsed": false, "input": [ "arr.shape" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 151, "text": [ "(5, 4)" ] } ], "prompt_number": 151 }, { "cell_type": "code", "collapsed": false, "input": [ "arr.ndim" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 152, "text": [ "2" ] } ], "prompt_number": 152 }, { "cell_type": "code", "collapsed": false, "input": [ "arr.dtype" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 153, "text": [ "dtype('int64')" ] } ], "prompt_number": 153 }, { "cell_type": "code", "collapsed": false, "input": [ "arr.size" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 154, "text": [ "20" ] } ], "prompt_number": 154 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Functions on arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Too many to name here but for example:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "sin(arr)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 155, "text": [ "array([[-0.99999021, 0.84147098, 0.90929743, 0.14112001],\n", " [-0.54402111, -0.99999021, -0.53657292, 0.42016704],\n", " [ 0.91294525, 0.83665564, -0.00885131, -0.8462204 ],\n", " [-0.98803162, -0.40403765, 0.55142668, 0.99991186],\n", " [ 0.74511316, -0.15862267, -0.91652155, -0.83177474]])" ] } ], "prompt_number": 155 }, { "cell_type": "code", "collapsed": false, "input": [ "sum(arr)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 156, "text": [ "441" ] } ], "prompt_number": 156 }, { "cell_type": "code", "collapsed": false, "input": [ "mean(arr), median(arr), arr.max(), arr.min()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 159, "text": [ "(22.050000000000001, 21.5, 43, 1)" ] } ], "prompt_number": 159 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Iterating" ] }, { "cell_type": "code", "collapsed": false, "input": [ "for row in arr:\n", " print row" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[11 1 2 3]\n", "[10 11 12 13]\n", "[20 21 22 23]\n", "[30 31 32 33]\n", "[40 41 42 43]\n" ] } ], "prompt_number": 160 }, { "cell_type": "code", "collapsed": false, "input": [ "for element in arr.flat:\n", " print element," ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "11 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 40 41 42 43\n" ] } ], "prompt_number": 161 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "View or shallow copies" ] }, { "cell_type": "code", "collapsed": false, "input": [ "c = arr.view()\n", "c" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 162, "text": [ "array([[11, 1, 2, 3],\n", " [10, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]])" ] } ], "prompt_number": 162 }, { "cell_type": "code", "collapsed": false, "input": [ "c is arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 163, "text": [ "False" ] } ], "prompt_number": 163 }, { "cell_type": "code", "collapsed": false, "input": [ "c.base is arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 164, "text": [ "True" ] } ], "prompt_number": 164 }, { "cell_type": "code", "collapsed": false, "input": [ "c.flags.owndata" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 165, "text": [ "False" ] } ], "prompt_number": 165 }, { "cell_type": "code", "collapsed": false, "input": [ "c.shape = [2, 10]\n", "c" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 170, "text": [ "array([[11, 1, 2, 3, 99, 11, 12, 13, 20, 21],\n", " [22, 23, 30, 31, 32, 33, 40, 41, 42, 43]])" ] } ], "prompt_number": 170 }, { "cell_type": "code", "collapsed": false, "input": [ "arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 171, "text": [ "array([[11, 1, 2, 3],\n", " [99, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]])" ] } ], "prompt_number": 171 }, { "cell_type": "code", "collapsed": false, "input": [ "c[0,4] = 99\n", "c, arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 172, "text": [ "(array([[11, 1, 2, 3, 99, 11, 12, 13, 20, 21],\n", " [22, 23, 30, 31, 32, 33, 40, 41, 42, 43]]),\n", " array([[11, 1, 2, 3],\n", " [99, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]]))" ] } ], "prompt_number": 172 }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make a deep (independent) copy:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "d = arr.copy()\n", "d[:] = 10\n", "d" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 173, "text": [ "array([[10, 10, 10, 10],\n", " [10, 10, 10, 10],\n", " [10, 10, 10, 10],\n", " [10, 10, 10, 10],\n", " [10, 10, 10, 10]])" ] } ], "prompt_number": 173 }, { "cell_type": "code", "collapsed": false, "input": [ "arr" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 174, "text": [ "array([[11, 1, 2, 3],\n", " [99, 11, 12, 13],\n", " [20, 21, 22, 23],\n", " [30, 31, 32, 33],\n", " [40, 41, 42, 43]])" ] } ], "prompt_number": 174 }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Graphing" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plot(a)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 175, "text": [ "[]" ] }, { "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD9CAYAAAC7iRw+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X9U1HWi//EnBlabaWY61IwubkAwimgmuu31NmlouUcu\nmbFhJYnunqunu7nbutXee7+r3ZNgnu7N7NLd28Ui0wV3OxfYrss1V7FaA1Ts11IxtZgz/PImYhoq\ngp/vH5MTKpIMw3xmmNfjnDkMn+Ez85q0Fx/f8/68PxGGYRiIiEjYGGR2ABERCSwVv4hImFHxi4iE\nGRW/iEiYUfGLiIQZFb+ISJjpsfizs7OxWCwkJSWds339+vUkJiYyfvx4HnvsMe/2nJwc4uLiSEhI\nYNu2bd7t+/btIykpibi4OB555BE/vwUREemNHot/0aJFlJWVnbNt586dlJaW8v777/Phhx/yi1/8\nAoCamhqKioqoqamhrKyMZcuWcfYUgaVLl5Kfn4/T6cTpdF7wnCIiEjg9Fv/06dMZPnz4OdteeOEF\nnnjiCaKiogAYOXIkAC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12li9fbnYcAFavXo3L5aKuro7C\nwkJmzJjBK6+8Ymqm6OhoRo8eTW1tLQDbt29n3LhxpmZKSEigoqKCEydOYBgG27dvx263m5rprLS0\nNAoKCgAoKCgIigMK8MysW7t2LSUlJVxxxRVmxyEpKYnm5mbq6uqoq6vDZrNRXV1t+i/K9PR0duzY\nAUBtbS3t7e2MGDHC1EyxsbHs2rULgB07dhAfH//tO/XHJ8+9tXXrViM+Pt648cYbjdWrV5sdxzAM\nw3jrrbeMiIgIIzk52Zg4caIxceJE449//KPZsbzKy8uDZlbPu+++a9xyyy3GhAkTjLvvvtv0WT2G\nYRhr1qwx7Ha7MX78eGPhwoXeWRiBdN999xnXX3+9ERUVZdhsNmPDhg3G4cOHjZkzZxpxcXFGamqq\nceTIEdNz5efnG7GxscaYMWO8f9eXLl1qSqbBgwd7/1t1NXbs2IDP6ukuU3t7u/HAAw8Y48ePN26+\n+WZj586dpmTq+ndqz549RkpKipGcnGxMmzbNqK6u/tbnCaoLsYiISP8zfahHREQCS8UvIhJmVPwi\nImFGxS8iEmZU/CIiYUbFLyISZv4/FlW3+SSU950AAAAASUVORK5CYII=\n" } ], "prompt_number": 175 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Great tutorial: http://scipy-lectures.github.io/intro/language/python_language.html\n", "\n", "Another more in depth tutorial: http://nbviewer.ipython.org/gist/rpmuller/5920182" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By: Andr\u00e9s Cabrera mantaraya36@gmail.com\n", "\n", "For course MAT 240E at UCSB\n", "\n", "This ipython notebook is licensed under the CC-BY-NC-SA license: http://creativecommons.org/licenses/by-nc-sa/4.0/\n", "\n", "![http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png](http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png)" ] } ], "metadata": {} } ] }