Created
July 22, 2014 23:51
-
-
Save jakevdp/ca2641e568bfe8c47926 to your computer and use it in GitHub Desktop.
Block Diagonal Stuff
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
| { | |
| "metadata": { | |
| "name": "", | |
| "signature": "sha256:7dd34d7c65e65c2f3c6f598480f4231b6b27ac192ec3577264e22355aa0d46e3" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "import numpy as np\n", | |
| "N = 3\n", | |
| "M = 2\n", | |
| "\n", | |
| "mats = [np.random.random((N, N)) for i in range(M)]\n", | |
| "\n", | |
| "X = np.zeros((N * M, N * M))\n", | |
| "for i in range(M):\n", | |
| " X[i * N: (i + 1) * N, i * N: (i + 1) * N] = mats[i]\n", | |
| " \n", | |
| "print(X)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[[ 0.72861009 0.61886456 0.868937 0. 0. 0. ]\n", | |
| " [ 0.58373219 0.05713773 0.54441987 0. 0. 0. ]\n", | |
| " [ 0.92424286 0.52670066 0.41588838 0. 0. 0. ]\n", | |
| " [ 0. 0. 0. 0.82193237 0.26313266 0.78248449]\n", | |
| " [ 0. 0. 0. 0.76988054 0.41347041 0.54500163]\n", | |
| " [ 0. 0. 0. 0.25286906 0.17003135 0.33396628]]\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 15 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "U, S, V = np.linalg.svd(X)\n", | |
| "print(U)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[[-0.68911493 0. -0.42665971 -0.5857321 0. 0. ]\n", | |
| " [-0.40573348 0. -0.44254771 0.79970737 0. 0. ]\n", | |
| " [-0.60041731 0. 0.78874141 0.1318561 0. 0. ]\n", | |
| " [ 0. -0.72157809 0. 0. -0.61288965 0.3220114 ]\n", | |
| " [ 0. -0.63518218 0. 0. 0.77109167 0.04428589]\n", | |
| " [ 0. -0.27544267 0. 0. -0.17258017 -0.94569943]]\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 25 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "U[0, 1] == 0" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "metadata": {}, | |
| "output_type": "pyout", | |
| "prompt_number": 28, | |
| "text": [ | |
| "True" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 28 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "for u,s,v in [np.linalg.svd(m) for m in mats]:\n", | |
| " print u" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "[[-0.68911493 -0.42665971 -0.5857321 ]\n", | |
| " [-0.40573348 -0.44254771 0.79970737]\n", | |
| " [-0.60041731 0.78874141 0.1318561 ]]\n", | |
| "[[-0.72157809 -0.61288965 0.3220114 ]\n", | |
| " [-0.63518218 0.77109167 0.04428589]\n", | |
| " [-0.27544267 -0.17258017 -0.94569943]]\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 22 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment