{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 style=\"text-align: center;\">NumPy Array Tutorial @ EuroScipy 2015</h1>\n",
    "\n",
    "<img src=\"images/euroscipy_logo.png\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Goal of this Tutorial\n",
    "\n",
    "- **Introduce the basics of Numpy**, and some more advanced stuff;\n",
    "- **Provide some concrete examples** where Numpy takes a central role.\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Schedule\n",
    "\n",
    "Outline:\n",
    "\n",
    "**14:00 - 14:15** Preliminaries\n",
    "\n",
    "- Making sure your computer is set up and everything is up&running\n",
    "\n",
    "** PART 1 ** Numpy Basics (14:15 - 16:30)\n",
    "\n",
    "**14:15 - 15:00** (45 mins) Introduction to Numpy\n",
    "\n",
    "- What is Numpy?\n",
    "- Introduction to Numpy Arrays\n",
    "    - Understand the importance of numpy arrays over lists\n",
    "- Numpy Data Types\n",
    "    - Conversion and Type Casting\n",
    "    - Numerical Representations\n",
    "- Record Array\n",
    "\n",
    "** 15:00 - 15:30 ** (30 mins) Indexing and Slicing\n",
    "\n",
    "- Indexing numpy arrays\n",
    "    - fancy indexing\n",
    "    - memory management\n",
    "- Slicing \n",
    "- Vectorization\n",
    "- Using arrays in Conditions\n",
    "\n",
    "** 15:30 - 15:45 ** (15 mins) Coffee Break\n",
    "\n",
    "** 15:45 - 16:15** (30 mins) Numpy Operations\n",
    "\n",
    "- Linear Algebra\n",
    "- Array and Matrix\n",
    "- Reshaping and Resizing\n",
    "\n",
    "\n",
    "** PART 2 ** Advanced Numpy Functions and Applications (16:30 - 17:30)\n",
    "\n",
    "** 16:15- 16:55 ** (40 mins) Data Processing\n",
    "\n",
    "- File I/0\n",
    "- Data Processing\n",
    "- Memmap and Serialization\n",
    "- `numexpr`\n",
    "\n",
    "** 16:55 - 17:25 ** (30 mins) Numpy Application (Machine Learning)\n",
    "\n",
    "- Machine Learning Intro\n",
    "- Clustering with scipy\n",
    "- Clustering with scikit-learn\n",
    "\n",
    "** 17:25 - 17:30 ** A look at the future (of Numpy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Requirements"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This tutorial requires the following packages:\n",
    "\n",
    "- Python version 2.7, 3.4+\n",
    "- `numpy` version 1.5 or later: http://www.numpy.org/\n",
    "- `scipy` version 0.9 or later: http://www.scipy.org/\n",
    "- `matplotlib` version 1.0 or later: http://matplotlib.org/\n",
    "- `ipython` version 1.0 or later, with notebook support: http://ipython.org\n",
    "\n",
    "(and for the *second part* of the tutorial):\n",
    "\n",
    "- `scikit-learn` version 0.12 or later: http://scikit-learn.org\n",
    "- `numexpr` version 2.4.1 or later: https://github.com/pydata/numexpr\n",
    "\n",
    "The easiest way to get these is to use an all-in-one installer such as [Anaconda](http://www.continuum.io/downloads) from Continuum. These are available for multiple architectures."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# How to setup your environment"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The simplest way"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The easiest way to get these is to use the [conda](https://store.continuum.io) environment manager. \n",
    "\n",
    "I suggest downloading and installing [miniconda](http://conda.pydata.org/miniconda.html).\n",
    "\n",
    "The following command will install all required packages:\n",
    "\n",
    "    $ conda install numpy scipy matplotlib scikit-learn ipython-notebook numexpr\n",
    "    \n",
    "Alternatively, you can download and install the (very large) **Anaconda software distribution**, found at [https://store.continuum.io/]()."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The \"longest\" way"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Create your **Virtual Environment** (highly suggested)\n",
    "\n",
    "    - `$ virtualenv -p <path to the python interpreter you want to fork> numpy_training`\n",
    "    - `$ source numpy_training/bin/activate`\n",
    "\n",
    "2. **pip** on the run\n",
    "    - `pip install numpy`\n",
    "    - `pip install scipy`\n",
    "    - `pip install matplotlib`\n",
    "    - `pip install \"ipython[all]\"  # don't forget the quotation!`\n",
    "    - `pip install scikit-learn`\n",
    "    - `pip install numexpr`\n",
    "    \n",
    "    **OR**\n",
    "    \n",
    "    - `pip install -r requirements.txt`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Alternatives\n",
    "\n",
    "- **Linux**: If you're on Linux, you can use the linux distribution tools \n",
    "\n",
    "    - Type, for example, `apt-get install numpy` or `yum install numpy`.\n",
    "    \n",
    "    \n",
    "\n",
    "- **Mac**: If you're on OSX, there are similar tools such as MacPorts or HomeBrew which contain pre-compiled versions of these packages.\n",
    "\n",
    "    - Just type `brew install numpy` in your terminal (if you're using HomeBrew)\n",
    "\n",
    "\n",
    "\n",
    "- **Windows**: Windows can be challenging: the best bet is probably to use a package installer such as Anaconda, above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python Version"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I'm currently running this tutorial with **Python 3** on **Anaconda*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python 3.4.3 :: Anaconda 2.3.0 (x86_64)\r\n"
     ]
    }
   ],
   "source": [
    "!python --version"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# How to test if everything is Up&Running"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Try running iPython with notebook support"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "!ipython notebook  # run this in your terminal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Try to import everything"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import scipy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "import numexpr as ne\n",
    "import sklearn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Check Installed Versions "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "numpy: 1.9.2\n",
      "scipy: 0.16.0\n",
      "matplotlib: 1.4.3\n",
      "iPython: 4.0.0\n",
      "scikit-learn: 0.16.1\n",
      "numexpr: 2.4.3\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "print('numpy:', numpy.__version__)\n",
    "\n",
    "import scipy\n",
    "print('scipy:', scipy.__version__)\n",
    "\n",
    "import matplotlib\n",
    "print('matplotlib:', matplotlib.__version__)\n",
    "\n",
    "import IPython\n",
    "print('iPython:', IPython.__version__)\n",
    "\n",
    "import sklearn\n",
    "print('scikit-learn:', sklearn.__version__)\n",
    "\n",
    "import numexpr\n",
    "print('numexpr:', numexpr.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. Enable the inline visualisation of plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<br>\n",
    "<hr>\n",
    "<h1 style=\"text-align: center;\">If everything worked down here, you're ready to start!</h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<br>\n",
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Consulting Material"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You have two options to go through the material presented in this tutorial:\n",
    "\n",
    "* Read (and execute) the material as **iPython/Jupyter** notebooks\n",
    "* (just) read the material as (HTML) slides"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the first case, all you need to do is just execute `ipython notebook` (or `jupyter notebook`) depending on the version of `iPython` you have installed on your machine\n",
    "\n",
    "(`jupyter` command works in case you have `iPython 4.0.x` installed)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the second case, you may simply convert the provided notebooks in `HTML` slides and see them into your browser\n",
    "thanks to `nbconvert`.\n",
    "\n",
    "Thus, move to the folder where notebooks are stored and execute the following command:\n",
    "\n",
    "    ipython nbconvert --to slides ./*.ipynb --post serve\n",
    "    \n",
    "   \n",
    "(Please substitute `ipython` with `jupyter` in the previous command if you have `iPython 4.x` installed on your machine)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## In case..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "..you wanna do **both** (interactive and executable slides), I highly suggest to install the terrific `RISE` ipython notebook extension: [https://github.com/damianavila/RISE]()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
