Commit b7aeb9d9 authored by Steve Tjoa's avatar Steve Tjoa

numpy basics

parent 576366a8
......@@ -209,7 +209,7 @@ div#notebook {
<li><a href="python_basics.html">Python Basics</a></li>
<li><a href="notebooks/get_good_at_ipython.ipynb">Getting Good at IPython</a></li>
<li><a href="ipython_audio.html">Using Audio in IPython</a> (<a href="ipython_audio.ipynb">ipynb</a>)</li>
<li><a href="notebooks/numpy_basics.ipynb">NumPy, SciPy, Matplotlib Basics</a></li>
<li><a href="numpy_basics.html">NumPy and SciPy Basics</a> (<a href="numpy_basics.ipynb">ipynb</a>)</li>
</ol>
</div>
......
......@@ -22,7 +22,7 @@
"1. [Python Basics](python_basics.html)\n",
"1. [Getting Good at IPython](notebooks/get_good_at_ipython.ipynb)\n",
"1. [Using Audio in IPython](ipython_audio.html) ([ipynb](ipython_audio.ipynb))\n",
"1. [NumPy, SciPy, Matplotlib Basics](notebooks/numpy_basics.ipynb)"
"1. [NumPy and SciPy Basics](numpy_basics.html) ([ipynb](numpy_basics.ipynb))"
]
},
{
......
{
"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": {}
}
]
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment