{
 "metadata": {
  "name": "",
  "signature": "sha256:0d9b8beade1a15c593193c13022afe6b01496f2e301388ec350e9680be209e28"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "NumPy, SciPy, and Matplotlib"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The quartet of NumPy, SciPy, Matplotlib, and IPython is a popular combination in the Python world. We will use each of these libraries in this workshop."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Tutorial"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[NumPy](http://www.numpy.org) is one of the most popular libraries for numerical computing in the world. It is used in several disciplines including image processing, finance, bioinformatics, and more.  This entire workshop is based upon NumPy and its derivatives.\n",
      "\n",
      "If you are new to NumPy, follow this [NumPy Tutorial](http://wiki.scipy.org/Tentative_NumPy_Tutorial).\n",
      "\n",
      "[SciPy](http://docs.scipy.org/doc/scipy/reference/) is a Python library for scientific computing which builds on top of NumPy. If NumPy is like the Matlab core, then SciPy is like the Matlab toolboxes. It includes support for linear algebra, sparse matrices, spatial data structions, statistics, and more.\n",
      "\n",
      "While there is a [SciPy Tutorial](http://docs.scipy.org/doc/scipy/reference/tutorial/index.html), it isn't critical that you follow it for this workshop."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Distance Metrics"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from scipy.spatial import distance\n",
      "print distance.euclidean([0, 0], [3, 4])\n",
      "print distance.sqeuclidean([0, 0], [3, 4])\n",
      "print distance.cityblock([0, 0], [3, 4])\n",
      "print distance.chebyshev([0, 0], [3, 4])\n",
      "print distance.cosine([1, 0], [0, 99])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "5.0\n",
        "25\n",
        "7\n",
        "4\n",
        "1.0\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Sorting"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "NumPy arrays have a method, `sort`, which sorts the array *in-place*."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = randn(5)\n",
      "print x\n",
      "x.sort()\n",
      "print x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[ 1.28550722 -1.14034515  0.06384698 -0.97859418  1.43006581]\n",
        "[-1.14034515 -0.97859418  0.06384698  1.28550722  1.43006581]\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "`numpy.argsort` returns an array of indices, `ind`, such that `x[ind]` is a sorted version of `x`."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = randn(5)\n",
      "print x\n",
      "ind = argsort(x)\n",
      "print ind\n",
      "print x[ind]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[-1.17264838  0.01291842 -0.10398369 -0.25878579 -0.50355634]\n",
        "[0 4 3 2 1]\n",
        "[-1.17264838 -0.50355634 -0.25878579 -0.10398369  0.01291842]\n"
       ]
      }
     ],
     "prompt_number": 4
    }
   ],
   "metadata": {}
  }
 ]
}