Commit e6950112 authored by Steve Tjoa's avatar Steve Tjoa

initial commit: basics of python, numpy, segmentation

parent 528ac1fd
{
"metadata": {
"name": "",
"signature": "sha256:52462b1d6020898bd104b0df2dee0679f90aa47a461d159d5e6c822a8020d7a4"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"NumPy, SciPy, and Matplotlib"
]
},
{
"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
{
"metadata": {
"name": "",
"signature": "sha256:4ced2ceb7a935191f56f4225788885407a0fa2d45199d124306c06f71cf0a75b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Python Basics"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"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.
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