Created
September 14, 2014 22:26
-
-
Save kanungo/3c04a963ce84d7fe7fa0 to your computer and use it in GitHub Desktop.
Linear Algebra with numpy
This file contains 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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"\n", | |
"a = [[1, 0], [0, 1]] \n", | |
"b = [[4, 1], [2, 2]]\n", | |
"c = np.dot(a, b)\n", | |
"print 'Dot product'\n", | |
"print c\n", | |
"\n", | |
"# Inner product with vectors\n", | |
"a = np.array([1,2,3])\n", | |
"b = np.array([0,1,0])\n", | |
"d = np.inner(a, b)\n", | |
"print 'Inner product'\n", | |
"print d\n", | |
"\n", | |
"# Inner product with arrays\n", | |
"a = np.arange(6).reshape((2,3))\n", | |
"b = np.arange(3)\n", | |
"e = np.inner(a, b)\n", | |
"print 'Outer product'\n", | |
"print e\n", | |
"\n", | |
"# Outer product\n", | |
"a = [1, 2]\n", | |
"b = [1, 2, 3]\n", | |
"f = np.outer(a, b)\n", | |
"print 'Inner product'\n", | |
"print f" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"\n", | |
"# Trace\n", | |
"a = np.eye(4)\n", | |
"print a\n", | |
"print np.trace(a)\n", | |
"\n", | |
"# Determinant\n", | |
"b = np.array([[ 13, 4, 5],\n", | |
" [ 6, 11, 8],\n", | |
" [ 9, 10, 5]])\n", | |
"print b\n", | |
"print np.linalg.det(b)\n", | |
"\n", | |
"# Transpose\n", | |
"c = np.array([[ 13, 4, 5, 57],\n", | |
" [ 6, 11, 8, 11]])\n", | |
"print c\n", | |
"print np.transpose(c)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment