<?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>Syntagmatic.net</title>
	<atom:link href="http://www.syntagmatic.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.syntagmatic.net</link>
	<description>now reading: Tropic of Cancer</description>
	<lastBuildDate>Mon, 15 Mar 2010 14:30:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lisp Reference</title>
		<link>http://www.syntagmatic.net/lisp-reference/</link>
		<comments>http://www.syntagmatic.net/lisp-reference/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 14:19:55 +0000</pubDate>
		<dc:creator>Kai</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://www.syntagmatic.net/?p=178</guid>
		<description><![CDATA[A collection of lisp snippets I&#8217;ll be adding to as I learn more. Factorial (recursive function) &#40;defun factorial &#40;n&#41; &#40;if &#40;= n 0&#41; 1 &#40;if &#40;&#62; n 0&#41; &#40;* n &#40;factorial &#40;- n 1&#41;&#41;&#41;&#41;&#41;&#41;]]></description>
			<content:encoded><![CDATA[<p>A collection of lisp snippets I&#8217;ll be adding to as I learn more.</p>
<h3>Factorial (recursive function)</h3>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> factorial <span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span>                                
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> n <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>                                       
    <span style="color: #cc66cc;">1</span>                                             
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> n <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>                                   
      <span style="color: #66cc66;">&#40;</span>* n <span style="color: #66cc66;">&#40;</span>factorial <span style="color: #66cc66;">&#40;</span>- n <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.syntagmatic.net/lisp-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Say&#8217;s Law</title>
		<link>http://www.syntagmatic.net/says-law/</link>
		<comments>http://www.syntagmatic.net/says-law/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 12:26:41 +0000</pubDate>
		<dc:creator>Kai</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[economics]]></category>

		<guid isPermaLink="false">http://www.syntagmatic.net/?p=154</guid>
		<description><![CDATA[Say&#8217;s Law, also known as the Law of Markets, is an important component of classical economics and formulated thus: It is worthwhile to remark that a product is no sooner created than it, from that instant, affords a market for other products to the full extent of its own value. When the producer has put [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Say%27s_law" title="Say's Law">Say&#8217;s Law</a>, also known as the Law of Markets, is an important component of classical economics and formulated thus:</p>
<blockquote><p>It is worthwhile to remark that a product is no sooner created than it, from that instant, affords a market for other products to the full extent of its own value. When the producer has put the finishing hand to his product, he is most anxious to sell it immediately, lest its value should diminish in his hands. Nor is he less anxious to dispose of the money he may get for it; for the value of money is also perishable. But the only way of getting rid of money is in the purchase of some product or other. Thus the mere circumstance of creation of one product immediately opens a vent for other products. (J.B. Say, 1803: p.138-9)</p></blockquote>
<p>In other words:</p>
<ul>
<li>Products create a market for themselves</li>
<li>They do this because producers are eager to exchange their products for their maximum value</li>
<li>The value of products degrades over time, so the producer is eager to exchange as soon as possible</li>
<li>The value of money degrades over time as well, so the producer is eager to exchange again for more product</li>
<li>Since the value of money is arbitrary and tied to the production and exchange of products, the products create a market for themselves</li>
</ul>
<p>This seems like it would hold in high-competition industries where the costs of learning about competing products are low (easy to shop around).  Money is a powerful symbol, and in this interpretation the money stands for products.  The relative rates of production determine the prices of products&#8211; implicitly creating demand.</p>
<p>Say&#8217;s law is a highly <a href="http://en.wikipedia.org/wiki/Say%27s_law#Assumptions_and_critiques" title="Assumptions of Say's Law">simplified view</a>, according to modern detractors like <a href="http://en.wikipedia.org/wiki/John_Maynard_Keynes" title="John Maynard Keynes">Keynes</a>.  Some of the more convincing critiques I found against the law were:</p>
<ul>
<li>If prices don&#8217;t move freely up and down, then money becomes disengaged from the value of the product.</li>
<li>Government intervention can create skewed supply.  This can be through subsidies, taxation, pricing laws, etc.</li>
<li>Speculation and investment in non-capital goods provide other places to &#8220;dispose of the money&#8221; besides acquiring a new, degradable product</li>
</ul>
<p>That last point is a bit confusing&#8211; but consider the purchase of one media company by a conglomerate.  The conglomerate is not investing strictly in the cameras, distribution capabilities, etc&#8211; it&#8217;s also investing in the talent, brand and audience the media company reaches (or has the potential to reach).  These are intangibles which may or may not pay off&#8211; but they&#8217;re not a product in the sense that Say&#8217;s was talking about.</p>
<p>On the other hand, there are farmer&#8217;s markets, which operate a lot like Say&#8217;s law.  In the morning the place is bustling, with the best products on the tables and money quickly changing hands.  People look to diversify their diets, and they consider trade-offs of all the products in the market.  I&#8217;m even eager to get rid of my money, as Say predicts, since I know the market has some of the best deals around.  As the day goes on, the crowd wanes and sellers drop their prices unloading the rest of their goods.  And money&#8217;s actually working like it should!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syntagmatic.net/says-law/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hidden Layer Neurons</title>
		<link>http://www.syntagmatic.net/hidden-layer-neurons/</link>
		<comments>http://www.syntagmatic.net/hidden-layer-neurons/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 02:41:02 +0000</pubDate>
		<dc:creator>Kai</dc:creator>
				<category><![CDATA[Writing]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[neural networks]]></category>
		<category><![CDATA[neuroscience]]></category>

		<guid isPermaLink="false">http://www.syntagmatic.net/?p=121</guid>
		<description><![CDATA[Hidden layer neurons are large groups of neurons between an input layer and output layer&#8211; your sensory receptors and your motor actions. Their size, type, and network topology (who connects to who) affect the complexity of problems they solve and decisions they make. Successful networks find solutions because they are statistically favored. Neurons compete for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.syntagmatic.net/wp-content/uploads/2009/10/GFPneuron.png"><img src="http://www.syntagmatic.net/wp-content/uploads/2009/10/GFPneuron.png" alt="Neuron" title="Neuron" width="400" height="319" class="size-full wp-image-124" style="padding:10px 0px 10px 24px;"/></a></p>
<p>Hidden layer neurons are large groups of neurons <em>between</em> an input layer and output layer&#8211; your sensory receptors and your motor actions.  Their size, type, and network topology (who connects to who) affect the complexity of problems they solve and decisions they make.  Successful networks find solutions because they are statistically favored.  Neurons compete for resources.  With successful predictions, they grow stronger.  Those that fail to make patterns out of chaos weaken.  These cells even contain programming to destroy themselves, a process called <a href="http://en.wikipedia.org/wiki/Apoptosis">apoptosis</a>.  This occurs at a rapid rate early in life as the brain first organizes itself, then slows down in adulthood.</p>
<p>We seem to be able to direct our own mental processes, somehow&#8211; which is absurd to me.  One part of the brain exerting control of another?  Different patterns resonating in electrochemical waves: metastable yet amplifying.  Consciousness subsuming itself with each passing moment.  Alive.  It seems awfully political: these neurons in such chaotic, demanding labor to produce a transient mind.  They are decision-making agents: competing for scarce resources, struggling for strong connections, forming computational alliances.  The competition for statistical significance may be experienced as a tug of attention, a drive to act, or a flash of inspiration.  The steps neurons take to assemble personal truth are invisible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syntagmatic.net/hidden-layer-neurons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Rollover Nav Bar</title>
		<link>http://www.syntagmatic.net/jquery-rollover-nav-bar/</link>
		<comments>http://www.syntagmatic.net/jquery-rollover-nav-bar/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 00:22:48 +0000</pubDate>
		<dc:creator>Kai</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[navigation]]></category>

		<guid isPermaLink="false">http://www.syntagmatic.net/?p=63</guid>
		<description><![CDATA[Here&#8217;s a simple jquery nav bar with animated rollover effects. The page titles roll up to reveal page descriptions underneath. This was originally designed for the Amuse Bouche Homepage. home twitters, and news! cast current cast and alumni! pics candids and nudes! vids la petite teet originals! mail join our mailing list! Here&#8217;s the jQuery, [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple jquery nav bar with animated rollover effects.  The page titles roll up to reveal page descriptions underneath.  This was originally designed for the <a href="http://www.amuseboucheimprov.com">Amuse Bouche Homepage</a>.<br />
<script src="http://www.syntagmatic.net/wp-content/uploads/2009/08/jquery-1.3.2.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://www.syntagmatic.net/wp-content/uploads/2009/08/style.css"/><script src="http://www.syntagmatic.net/wp-content/uploads/2009/08/hover.js" type="text/javascript"></script></p>
<div id="nav_bar" style="margin-bottom:18px;">
<div id="home">
<div class="nav_top">
<h2>home</h2>
</div>
<div class="nav_bottom">twitters, and news!</div>
</div>
<div id="cast">
<div class="nav_top">
<h2>cast</h2>
</div>
<div class="nav_bottom">current cast<br />
and alumni!</div>
</div>
<div id="pictures">
<div class="nav_top">
<h2>pics</h2>
</div>
<div class="nav_bottom">candids and<br />
nudes!</div>
</div>
<div id="videos">
<div class="nav_top">
<h2>vids</h2>
</div>
<div class="nav_bottom">la petite teet<br />
originals!</div>
</div>
<div id="mail">
<div class="nav_top">
<h2>mail</h2>
</div>
<div class="nav_bottom">join our<br />
mailing list!</div>
</div>
</div>
<p>Here&#8217;s the jQuery, hover.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0099aa; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0099aa; font-weight: bold;">var</span> navButtons <span style="color: #339933;">=</span> <span style="color: #6699CC;">'#home, #cast, #pictures, #videos, #mail'</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span>navButtons<span style="color: #009900;">&#41;</span>.<span style="color: #dd00ff;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #0099aa; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #0099aa; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #0099aa;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #dd00ff;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #6699CC;">'top'</span><span style="color: #339933;">:</span><span style="color: #6699CC;">'-30px'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0099aa; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #0099aa; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #0099aa;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #dd00ff;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #6699CC;">'top'</span><span style="color: #339933;">:</span><span style="color: #6699CC;">'0px'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-63"></span></p>
<p><strong>style.css</strong>, color scheme &#8220;Sunrise over Myanmar&#8221; by pixelperfectt on <a href="http://kuler.adobe.com/">Kuler</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc66cc;">#nav_bar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">float</span><span style="color: #00AA00;">:</span><span style="color: #333333;">top</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">margin</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">0px</span> <span style="color: #aa8888;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">position</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">width</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">500px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">height</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#home</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">#cast</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">#pictures</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">#videos</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">#mail</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">float</span><span style="color: #00AA00;">:</span><span style="color: #333333;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">width</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">70px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">height</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">60px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">15px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">font-family</span><span style="color: #ffffff;">:sans-</span>serif<span style="color: #00AA00;">;</span>
    <span style="color: #333333;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#ffffff</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">border</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">0px</span> <span style="color: #aa8888;">solid</span> <span style="color: #aa8888;">white</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">position</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#nav_bar</span> h2 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">15px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">margin</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">padding</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.nav_top</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.nav_bottom</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">height</span><span style="color: #00AA00;">:</span><span style="color: #aa8888;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #333333;">float</span><span style="color: #00AA00;">:</span><span style="color: #333333;">top</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#home</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#29131F</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#cast</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#522125</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#pictures</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#7F2922</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#videos</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#C24D23</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc66cc;">#mail</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #333333;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">#DB7422</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>index.html</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Put the following two lines in the &lt;head&gt; section --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #ff7700;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;jquery-1.3.2.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #ff7700;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;hover.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">script</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- The menu --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bar&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;home&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_top&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #ff7700;">h2</span>&gt;</span>home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">h2</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bottom&quot;</span>&gt;</span>twitters, dates,and news!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;cast&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_top&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #ff7700;">h2</span>&gt;</span>cast<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">h2</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bottom&quot;</span>&gt;</span>current castand alumni!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;pictures&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_top&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #ff7700;">h2</span>&gt;</span>pics<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">h2</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bottom&quot;</span>&gt;</span>candids andnudes!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;videos&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_top&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #ff7700;">h2</span>&gt;</span>vids<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">h2</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bottom&quot;</span>&gt;</span>la petite teetoriginals!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;mail&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_top&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #ff7700;">h2</span>&gt;</span>mail<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">h2</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #ff7700;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #0099aa;">&quot;nav_bottom&quot;</span>&gt;</span>join ourmailing list!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #ff7700;">div</span>&gt;</span></pre></div></div>

<p>You&#8217;ll also need <a href="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js">jquery-1.3.2</a>, though you should try the newest version of <a href="http://jquery.com/">jQuery</a> first.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syntagmatic.net/jquery-rollover-nav-bar/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Matrix Multiplication in Python</title>
		<link>http://www.syntagmatic.net/matrix-multiplication-in-python/</link>
		<comments>http://www.syntagmatic.net/matrix-multiplication-in-python/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 08:33:08 +0000</pubDate>
		<dc:creator>Kai</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.syntagmatic.net/?p=3</guid>
		<description><![CDATA[In this tutorial we&#8217;ll look at some simple matrix multiplication tools in Python. The arrays are constructed using lists within lists, and the multiplication itself is implemented using for loops. The program works well for small arrays, but really starts bogging down at sizes 500&#215;500 and above. Anyone doing serious work will want to check [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Matrix_multiplication"><img class="alignright" src="http://upload.wikimedia.org/math/6/f/1/6f124ffad3022f9f1d4f51ca4e4b65e5.png" title="Matrix Multiplication" width="177" height="48" /></a></p>
<p>In this tutorial we&#8217;ll look at some simple matrix multiplication tools in Python.  The arrays are constructed using lists within lists, and the multiplication itself is implemented using for loops.  The program works well for small arrays, but really starts bogging down at sizes 500&#215;500 and above.  Anyone doing serious work will want to check out <a href="http://numpy.scipy.org/">NumPy</a>, which has matrix operations built-in and runs several thousand times faster.  In Part 2 I&#8217;ll compare NumPy&#8217;s performance to other optimized methods.</p>
<p>Let&#8217;s feast our eyes on the function definitions we&#8217;ll be using in <a href='http://www.syntagmatic.net/wp-content/uploads/2009/08/matrix.py'>matrix.py</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;">import</span> <span style="color: #a01010;">random</span>
<span style="color: #ff7700;">from</span> <span style="color: #a01010;">time</span> <span style="color: #ff7700;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;">import</span> cProfile
&nbsp;
<span style="color: #ff7700;">def</span> zero<span style="color: #888888;">&#40;</span>m,n<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># Create zero matrix</span>
    new_matrix = <span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span> <span style="color: #ff7700;">for</span> row <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span>n<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#93;</span> <span style="color: #ff7700;">for</span> col <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span>m<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#93;</span>
    <span style="color: #ff7700;">return</span> new_matrix
&nbsp;
<span style="color: #ff7700;">def</span> rand<span style="color: #888888;">&#40;</span>m,n<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># Create random matrix</span>
    new_matrix = <span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #a01010;">random</span>.<span style="color: #a01010;">random</span><span style="color: #888888;">&#40;</span><span style="color: #888888;">&#41;</span> <span style="color: #ff7700;">for</span> row <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span>n<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#93;</span> <span style="color: #ff7700;">for</span> col <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span>m<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#93;</span>
    <span style="color: #ff7700;">return</span> new_matrix
&nbsp;
<span style="color: #ff7700;">def</span> show<span style="color: #888888;">&#40;</span>matrix<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># Print out matrix</span>
    <span style="color: #ff7700;">for</span> col <span style="color: #ff7700;">in</span> matrix:
        <span style="color: #ff7700;">print</span> col 
&nbsp;
<span style="color: #ff7700;">def</span> mult<span style="color: #888888;">&#40;</span>matrix1,matrix2<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># Matrix multiplication</span>
    <span style="color: #ff7700;">if</span> <span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix1<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix2<span style="color: #888888;">&#41;</span>:
        <span style="color: #888888; font-style: italic;"># Check matrix dimensions</span>
        <span style="color: #ff7700;">print</span> <span style="color: #FFA500;">'Matrices must be m*n and n*p to multiply!'</span>
    <span style="color: #ff7700;">else</span>:
        <span style="color: #888888; font-style: italic;"># Multiply if correct dimensions</span>
        new_matrix = zero<span style="color: #888888;">&#40;</span><span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix1<span style="color: #888888;">&#41;</span>,<span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix2<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#41;</span><span style="color: #888888;">&#41;</span>
        <span style="color: #ff7700;">for</span> i <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix1<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#41;</span>:
            <span style="color: #ff7700;">for</span> j <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix2<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#41;</span><span style="color: #888888;">&#41;</span>:
                <span style="color: #ff7700;">for</span> k <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">range</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">len</span><span style="color: #888888;">&#40;</span>matrix2<span style="color: #888888;">&#41;</span><span style="color: #888888;">&#41;</span>:
                    new_matrix<span style="color: #888888;">&#91;</span>i<span style="color: #888888;">&#93;</span><span style="color: #888888;">&#91;</span>j<span style="color: #888888;">&#93;</span> += matrix1<span style="color: #888888;">&#91;</span>i<span style="color: #888888;">&#93;</span><span style="color: #888888;">&#91;</span>k<span style="color: #888888;">&#93;</span><span style="color: #66cc66;">*</span>matrix2<span style="color: #888888;">&#91;</span>k<span style="color: #888888;">&#93;</span><span style="color: #888888;">&#91;</span>j<span style="color: #888888;">&#93;</span>
        <span style="color: #ff7700;">return</span> new_matrix
&nbsp;
<span style="color: #ff7700;">def</span> time_mult<span style="color: #888888;">&#40;</span>matrix1,matrix2<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># Clock the time matrix multiplication takes</span>
    start = clock<span style="color: #888888;">&#40;</span><span style="color: #888888;">&#41;</span>
    new_matrix = mult<span style="color: #888888;">&#40;</span>matrix1,matrix2<span style="color: #888888;">&#41;</span>
    end = clock<span style="color: #888888;">&#40;</span><span style="color: #888888;">&#41;</span>
    <span style="color: #ff7700;">print</span> <span style="color: #FFA500;">'Multiplication took '</span>,end-start,<span style="color: #FFA500;">' seconds'</span>
&nbsp;
<span style="color: #ff7700;">def</span> profile_mult<span style="color: #888888;">&#40;</span>matrix1,matrix2<span style="color: #888888;">&#41;</span>:
    <span style="color: #888888; font-style: italic;"># A more detailed timing with process information</span>
    <span style="color: #888888; font-style: italic;"># Arguments must be strings for this function</span>
    <span style="color: #888888; font-style: italic;"># eg. profile_mult('a','b')</span>
    cProfile.<span style="color: #888888;">run</span><span style="color: #888888;">&#40;</span><span style="color: #FFA500;">'matrix.mult('</span> + matrix1 + <span style="color: #FFA500;">','</span> + matrix2 + <span style="color: #FFA500;">')'</span><span style="color: #888888;">&#41;</span></pre></div></div>

<p><span id="more-3"></span></p>
<p>Load the script into an interactive Python session:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;">import</span> matrix
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">zero</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">1</span>,<span style="color: #66cc66;">5</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a
<span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">zero</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">5</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b
<span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span>, <span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span>, <span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">show</span><span style="color: #888888;">&#40;</span>b<span style="color: #888888;">&#41;</span>        <span style="color: #888888; font-style: italic;"># This function makes arrays more readable.</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span></pre></div></div>

<p>Try multiplying zero matrices just to check the resulting dimensions:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">zero</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">2</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">zero</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">4</span>,<span style="color: #66cc66;">5</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c = matrix.<span style="color: #888888;">mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
Matrices must be m<span style="color: #66cc66;">*</span>n <span style="color: #ff7700;">and</span> n<span style="color: #66cc66;">*</span>p to multiply<span style="color: #66cc66;">!</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">zero</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">5</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c = matrix.<span style="color: #888888;">mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">show</span><span style="color: #888888;">&#40;</span>c<span style="color: #888888;">&#41;</span>        <span style="color: #888888; font-style: italic;"># Note that we end up with an n by p matrix</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span>           <span style="color: #888888; font-style: italic;"># In this case 2x5</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span>, <span style="color: #66cc66;">0</span><span style="color: #888888;">&#93;</span></pre></div></div>

<p>Now do some calculations:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> a = <span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #66cc66;">2</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#93;</span>         <span style="color: #888888; font-style: italic;"># 1x2 matrix</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = <span style="color: #888888;">&#91;</span><span style="color: #888888;">&#91;</span><span style="color: #66cc66;">1</span><span style="color: #888888;">&#93;</span>,<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">5</span><span style="color: #888888;">&#93;</span><span style="color: #888888;">&#93;</span>       <span style="color: #888888; font-style: italic;"># 2x1 matrix</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c = matrix.<span style="color: #888888;">mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">show</span><span style="color: #888888;">&#40;</span>c<span style="color: #888888;">&#41;</span>      <span style="color: #888888; font-style: italic;"># [1x2] * [2x1] --&gt; [1x1] matrix</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">17</span><span style="color: #888888;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> c = matrix.<span style="color: #888888;">mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">show</span><span style="color: #888888;">&#40;</span>c<span style="color: #888888;">&#41;</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">1.5756730190235944</span>, <span style="color: #66cc66;">0.70870079587302315</span>, <span style="color: #66cc66;">0.94109431416086442</span><span style="color: #888888;">&#93;</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">0.48198264627485315</span>, <span style="color: #66cc66;">0.32042216800153944</span>, <span style="color: #66cc66;">0.36885894389577889</span><span style="color: #888888;">&#93;</span>
<span style="color: #888888;">&#91;</span><span style="color: #66cc66;">1.2931982570350344</span>, <span style="color: #66cc66;">0.85088650318922798</span>, <span style="color: #66cc66;">1.1630298461072877</span><span style="color: #888888;">&#93;</span></pre></div></div>

<p>We can time the multiplication with the last two functions.  Try increasing the matrix sizes and see what happens:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">3</span>,<span style="color: #66cc66;">3</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">time_mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
Multiplication took  <span style="color: #66cc66;">0.0</span>  seconds     <span style="color: #888888; font-style: italic;"># 0.o</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">300</span>,<span style="color: #66cc66;">300</span><span style="color: #888888;">&#41;</span>          <span style="color: #888888; font-style: italic;"># Each matrix has 90000 elements now</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">300</span>,<span style="color: #66cc66;">300</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">time_mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
Multiplication took  <span style="color: #66cc66;">10.35</span>  seconds   <span style="color: #888888; font-style: italic;"># Many more calculations happening</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">600</span>,<span style="color: #66cc66;">600</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> b = matrix.<span style="color: #888888;">rand</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">600</span>,<span style="color: #66cc66;">600</span><span style="color: #888888;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">time_mult</span><span style="color: #888888;">&#40;</span>a,b<span style="color: #888888;">&#41;</span>
Multiplication took  <span style="color: #66cc66;">91.05</span>  seconds   <span style="color: #888888; font-style: italic;"># Not worth going much larger</span></pre></div></div>

<p>Take a look at the matrix multiplication loop, mult(matrix1,matrix2).  It&#8217;s iterating over i, j, and k &#8212; each of which is a column or row of a 600&#215;600 matrix.  600^3 = 216 million cycles through Python for loops.  That&#8217;s <em>O</em>(n^3) complexity, which is quite the pain for large arrays.  Take a look at the results of the profiler:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> matrix.<span style="color: #888888;">profile_mult</span><span style="color: #888888;">&#40;</span><span style="color: #FFA500;">'a'</span>,<span style="color: #FFA500;">'b'</span><span style="color: #888888;">&#41;</span>
         <span style="color: #66cc66;">721811</span> function calls <span style="color: #ff7700;">in</span> <span style="color: #66cc66;">91.598</span> CPU seconds
&nbsp;
   Ordered by: standard name
&nbsp;
   ncalls  tottime  percall  cumtime  percall filename:lineno<span style="color: #888888;">&#40;</span>function<span style="color: #888888;">&#41;</span>
        <span style="color: #66cc66;">1</span>    <span style="color: #66cc66;">0.005</span>    <span style="color: #66cc66;">0.005</span>   <span style="color: #66cc66;">91.598</span>   <span style="color: #66cc66;">91.598</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span>:<span style="color: #66cc66;">1</span><span style="color: #888888;">&#40;</span><span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span><span style="color: #888888;">&#41;</span>
        <span style="color: #66cc66;">1</span>   <span style="color: #66cc66;">89.996</span>   <span style="color: #66cc66;">89.996</span>   <span style="color: #66cc66;">91.593</span>   <span style="color: #66cc66;">91.593</span> matrix.<span style="color: #888888;">py</span>:<span style="color: #66cc66;">20</span><span style="color: #888888;">&#40;</span>mult<span style="color: #888888;">&#41;</span>
        <span style="color: #66cc66;">1</span>    <span style="color: #66cc66;">0.080</span>    <span style="color: #66cc66;">0.080</span>    <span style="color: #66cc66;">0.088</span>    <span style="color: #66cc66;">0.088</span> matrix.<span style="color: #888888;">py</span>:<span style="color: #66cc66;">5</span><span style="color: #888888;">&#40;</span>zero<span style="color: #888888;">&#41;</span>
   <span style="color: #66cc66;">360605</span>    <span style="color: #66cc66;">0.049</span>    <span style="color: #66cc66;">0.000</span>    <span style="color: #66cc66;">0.049</span>    <span style="color: #66cc66;">0.000</span> <span style="color: #888888;">&#123;</span><span style="color: #66cc66;">len</span><span style="color: #888888;">&#125;</span>
        <span style="color: #66cc66;">1</span>    <span style="color: #66cc66;">0.000</span>    <span style="color: #66cc66;">0.000</span>    <span style="color: #66cc66;">0.000</span>    <span style="color: #66cc66;">0.000</span> <span style="color: #888888;">&#123;</span>method <span style="color: #FFA500;">'disable'</span> of <span style="color: #FFA500;">'_lsprof.Profiler'</span> objects<span style="color: #888888;">&#125;</span>
   <span style="color: #66cc66;">361202</span>    <span style="color: #66cc66;">1.468</span>    <span style="color: #66cc66;">0.000</span>    <span style="color: #66cc66;">1.468</span>    <span style="color: #66cc66;">0.000</span> <span style="color: #888888;">&#123;</span><span style="color: #66cc66;">range</span><span style="color: #888888;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.syntagmatic.net/matrix-multiplication-in-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

