{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "a = np.random.randn(3)\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "array([ 0.4951792 , -1.03530404, 1.70427995])" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's zero out $a_2$:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "G = np.zeros((3, 3))\n", "\n", "c = a[0]/sqrt(a[0]**2 + a[1]**2)\n", "s = a[1]/sqrt(a[0]**2 + a[1]**2)\n", "\n", "G[:2,:2] = np.array([\n", " [c, s],\n", " [-s, c]\n", " ])\n", "G" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 3, "text": [ "array([[ 0.43147946, -0.90212276, 0. ],\n", " [ 0.90212276, 0.43147946, 0. ],\n", " [ 0. , 0. , 0. ]])" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Anything wrong with $G$?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "(Edit this cell for solution.)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "np.dot(G, a)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "array([ 1.14763099, 0. , 0. ])" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Observations?" ] } ], "metadata": {} } ] }