<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codebreaker &#187; linear algebra</title>
	<atom:link href="http://blog.sumin.us/archives/tag/linear-algebra/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.sumin.us</link>
	<description>2bc08752a0894eb2c7afb345286e391d</description>
	<lastBuildDate>Wed, 08 Sep 2010 02:15:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Finding Gram Matrix</title>
		<link>http://blog.sumin.us/archives/1196</link>
		<comments>http://blog.sumin.us/archives/1196#comments</comments>
		<pubDate>Mon, 07 Dec 2009 20:07:37 +0000</pubDate>
		<dc:creator>Sumin</dc:creator>
				<category><![CDATA[mathematics]]></category>
		<category><![CDATA[linear algebra]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.sumin.us/?p=1196</guid>
		<description><![CDATA[Matrix manipulation by hand is often times pain in the neck when it comes to anything bigger than 2 by 2 matrices as it involves a quite amount of arithmetic operations. Well, I've got an Intel Core 2 Duo processor and Python. No reason not to take advantage of them ;-) Source Code __author__ = [...]]]></description>
			<content:encoded><![CDATA[<p>Matrix manipulation by hand is often times pain in the neck when it comes to anything bigger than 2 by 2 matrices as it involves a quite amount of arithmetic operations. Well, I've got an Intel Core 2 Duo processor and Python. No reason not to take advantage of them ;-)</p>

<h3>Source Code</h3>

<pre><code>__author__ = 'Sumin Byeon &lt;sumin@cs.arizona.edu&gt;'

from Numeric import *

# u and v are lists of same lengths
def inner_product(u, v):
    return reduce(int.__add__, map(lambda x: x[0]*x[1], zip(u, v)))

# vs: a list of vectors
def gram_matrix(*vs):
    n = len(vs)
    mx = zeros((n, n))
    for i in range(0, n):
        for j in range(0, n):
            mx[i,j] = inner_product(vs[i], vs[j])
    return mx
</code></pre>

<h3>Result</h3>

<pre><code>&gt;&gt;&gt; gram_matrix([1,0,0,1], [-2,1,0,0], [-1,0,-1,0], [0,2,-3,0])
[[ 2 -2 -1  0]
 [-2  5  2  2]
 [-1  2  2  3]
 [ 0  2  3 13]]
</code></pre>
<!-- AdSense Now! V1.83 -->
<!-- Post[count: 2] -->
<div class="adsense adsense-leadout" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-2353453386862167";
/* 468x60, created 10/26/09 */
google_ad_slot = "1252542387";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sumin.us/archives/1196/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
