Created
January 23, 2017 10:11
-
-
Save drvinceknight/4bb764123a8a5dac33f2abb9a7f1150c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"There are a number of tremendously useful external libraries that you can install and use. **If you are using Anaconda** then most of these are already installed.\n", | |
"\n", | |
"If not, open a terminal (Mac OSX) or a command prompt (Windows) and type:\n", | |
"\n", | |
"```\n", | |
"pip install <name of library>\n", | |
"```\n", | |
"\n", | |
"replacing `<name of library>` with the actual name of the library. Here are some examples of libraries:\n", | |
"\n", | |
"- Sympy: symbolic computation library\n", | |
"- Numpy: high performance numeric library\n", | |
"\n", | |
"For example to install the above we'd write:\n", | |
"\n", | |
"```\n", | |
"pip install sympy\n", | |
"pip install numpy\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Using sympy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import sympy as sym # Sympy is a library for symbolic mathematics\n", | |
"sym.init_printing() # Use LaTex to " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"x, y = sym.symbols('x, y')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAEEAAAAUBAMAAAAgmk0yAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIma7zZnddlTvRIkQ\nqzLsm4+cAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABIElEQVQoFX2SPU7DQBSEv8SJY2InRCAhoFpu\nwE+NWG4QQWpIBZRuohQIhSOkpqKiTRqUdjuLIhJHyA1CgYSEEOKtJSu20WaKt+ud8Xj83kJF4caB\npbbdPLQ6wp6vU0Qaqt11CmbgWx833mDHzVqm9sxAluRh/z4uKaNBzJ4h7HIM0bR66+uSIgzGjCSm\n5g5CE/4E5Ti7dc0JBH2exIPaYckBzEbMF7Q/rAI2yynkbGLav6lCvgLLha1F9GiModm3SQMzomGK\nPJzivadJX8Xv8Ywtos+i5pKJgvqUF5gPkwt5uDHkMZ9dd6Rji1zX//1wT16Qlq8mF+YdaOnoWw5k\nchxlRJJt0tVXnrTATn91g1TKZKU5vJKtJ1GoKCkuyC38A1GsMPc/smFjAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$\\left ( x, \\quad y\\right )$$" | |
], | |
"text/plain": [ | |
"(x, y)" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"x, y" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"We can solve linear equations using `solveset`:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAIYAAAA/BAMAAADXkq0fAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMrtUdhCZiUSr72bd\nIs25ozBRAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADtElEQVRYCe1XP2gTURj/YnKXP72XdHJtVZzN\n1E2SQToo0hu6VIo5rBRcNCDYwSEZxaVBEASFBN2k1G4OLlEQqSgNSF3UNg4OCpJobetgre9978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EFdh5UbtQxUdAP5zeG9Qjn87\niGPEm+vXy3Wx8hD/VgJstpGD0K+uoa1S5K31/NAUhlxffFMNQ6TuJXk9Okw/7SGdquw0tyQacC5p\nH3nrA/bK8hiCf72YOCexs60eAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$\\left\\{- \\frac{\\sqrt{2} i}{2}, \\frac{\\sqrt{2} i}{2}\\right\\}$$" | |
], | |
"text/plain": [ | |
"⎧-√2⋅ⅈ √2⋅ⅈ⎫\n", | |
"⎨──────, ────⎬\n", | |
"⎩ 2 2 ⎭" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sym.solveset(2 * x ** 2 + 1, x)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Using Numpy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[1, 2],\n", | |
" [3, 4]])" | |
] | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"array = np.array([[1, 2], [3, 4]]) # Creating a numpy array\n", | |
"array" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[-2, -1],\n", | |
" [ 0, 1]])" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"array - 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[5, 0, 3],\n", | |
" [3, 7, 9],\n", | |
" [3, 5, 2]])" | |
] | |
}, | |
"execution_count": 36, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"np.random.seed(0) # numpy has it's own random number generator\n", | |
"A = np.random.randint(0, 10, (3, 3)) # We can easily create a 3 by 3 array of random numbers\n", | |
"A" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(array([0, 1, 0]), array([2, 2, 2]))" | |
] | |
}, | |
"execution_count": 37, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"u = np.random.randint(0, 2, 3)\n", | |
"v = np.random.randint(2, 4, 3)\n", | |
"u, v" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 38, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"38" | |
] | |
}, | |
"execution_count": 38, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"np.dot(np.dot(u, A), v) # Matrix mulitplication u * A * v" | |
] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [default]", | |
"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.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment