<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Ivan Idris Blog</title>
	<atom:link href="http://ivanidris.net/wordpress/index.php/feed" rel="self" type="application/rss+xml" />
	<link>http://ivanidris.net/wordpress</link>
	<description>Author of NumPy Beginner&#039;s Guide</description>
	<lastBuildDate>Sun, 05 Feb 2012 09:39:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>NumPy Project Euler Problem 6</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/02/05/numpy-project-euler-problem-6</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/02/05/numpy-project-euler-problem-6#comments</comments>
		<pubDate>Sun, 05 Feb 2012 09:35:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=260</guid>
		<description><![CDATA[Project Euler Problem 6 is perfect to demonstrate the power of NumPy. No loops are required and only a few lines of code.
1. Create an array with the first 100 natural numbers
First we will create a NumPy array of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/problem=6">Project Euler Problem 6</a> is perfect to demonstrate the power of <a href="http://numpy.scipy.org/">NumPy</a>. No loops are required and only a few lines of code.</p>
<h3><strong>1. Create an array with the first 100 natural numbers</strong></h3>
<p>First we will create a NumPy array of the numbers 1 &#8211; 100 with the arange function.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">101</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>2. Sum the squares of the numbers</strong></h3>
<p>Second we will sum the squares of the numbers with the sum function.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sum_squares = numpy.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>3. Square the sum of the numbers</strong></h3>
<p>The NumPy ndarray class has a sum method, that we can use to sum the numbers in our array. After that calculate the square of the sum.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">square_sum = a.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span></pre></div></div>

<p>Below is the complete solution.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> square_sum - sum_squares</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy
&nbsp;
<span style="color: #808080; font-style: italic;">#The sum of the squares of the first ten natural numbers is,</span>
<span style="color: #808080; font-style: italic;">#1 ** 2 + 2 ** 2 + ... + 10 ** 2 = 385</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#The square of the sum of the first ten natural numbers is,</span>
<span style="color: #808080; font-style: italic;">#(1 + 2 + ... + 10) ** 2 = 55 ** 2 = 3025</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 1. Create an array with the first 100 natural numbers</span>
a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">101</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 2. Sum the squares of the numbers</span>
sum_squares = numpy.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> 
&nbsp;
<span style="color: #808080; font-style: italic;"># 3. Square the sum of the numbers</span>
square_sum = a.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Calculate the difference</span>
<span style="color: #ff7700;font-weight:bold;">print</span> square_sum - sum_squares</pre></div></div>

<p>&nbsp;</p>
<p>If you liked this post and are interested in NumPy check out <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy Beginner&#8217;s Guide</a> by yours truly.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F02%2F05%2Fnumpy-project-euler-problem-6&amp;title=NumPy%20Project%20Euler%20Problem%206" id="wpa2a_2"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/02/05/numpy-project-euler-problem-6/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[NumPy Project Euler]]></series:name>
	</item>
		<item>
		<title>Linear Algebra Book review</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/02/03/linear-algebra-book-review</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/02/03/linear-algebra-book-review#comments</comments>
		<pubDate>Fri, 03 Feb 2012 19:13:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=257</guid>
		<description><![CDATA[I had to read &#8220;Linear Algebra and Its Applications&#8221; by David Lay for the Linear Algebra 1 class in my first semester in University. So this is a gentle introduction to Linear Algebra. The book doesn&#8217;t assume a lot of [...]]]></description>
			<content:encoded><![CDATA[<p>I had to read &#8220;Linear Algebra and Its Applications&#8221; by David Lay for the Linear Algebra 1 class in my first semester in University. So this is a gentle introduction to Linear Algebra. The book doesn&#8217;t assume a lot of previous knowledge.</p>
<div align="center">
<a href="http://s724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/DSCN1862.jpg" rel="lightbox[linalg]"><img src="http://i724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/th_DSCN1862.jpg" border="0" alt="Linear Algebra Book" ></a>
</div>
<table>
<tr>
<td><b>Author</b></td>
<td>David C. Lay</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0201845563</td>
</tr>
</table>
<h3><b>Chapter Structure</b></h3>
<p>Each chapter starts with an introductory example. Each section within a chapter ends with practice problems and exercises. Worked out examples with solutions are given too. As you would expect from a Linear Algebra book, there are lots of theorems and numerical notes.</p>
<h3><b>1. Systems of Linear Equations</b></h3>
<p>The first chapter gives some examples of linear systems. The row reduction algorithm is explained. I remember having to solve these kind of problems by hand for weeks. As is usual in mathematics, we learn to work out something with paper and pencil the hard way and then we figure out how to do it faster by writing a computer program. If you are into Python, please check out <a href="http://numpy.scipy.org/">NumPy</a>.</p>
<h3><b>2. Vector and Matrix Equations</b></h3>
<p>Chapter 2 starts with a number of examples as well. We learn about the fundamental idea of representing a linear combination of vectors as a product of a matrix and a vector. This leads to this famous equation:</p>
<div align="center">
<p>A x = b</p>
</div>
<h3><b>3. Matrix Algebra</b></h3>
<p>Chapter 3 teaches about matrix operations such as matrix multiplication, matrix inversion and transposing matrices. The chapter ends with the Leontief Input Output Model from economics and applications to computer graphics.</p>
<h3><b>4. Determinants</b></h3>
<p>The introductory example in this chapter is about determinants in analytic geometry. Properties of determinants are mentioned as well as calculation methods.</p>
<h3><b>5. Vector Spaces</b></h3>
<p>I don&#8217;t know if it has anything to do with the chapter title, but the first example of this chapter is about space flight and control systems. In my opinion this chapter is more theoretical than the preceding chapters. The chapter ends with applications to difference equations and Markov Chains.</p>
<h3><b>6. Eigenvalues and Eigenvectors</b></h3>
<p>Dynamical systems and spotted owls are the topic of the introductory example of chapter 6. This chapter covers amongst others the characteristic equation, diagonalization and iterative algorithms to estimate eigenvalues.</p>
<h3><b>7. Orthogonality and Least Squares</b></h3>
<p>Chapter 7 begins with a short text about the North American Datum. After that we continue with sections on:</p>
<ul>
<li>orthogonality</li>
<li>orthogonal sets</li>
<li>orthogonal projections</li>
<li>the Gram-Schmidt process</li>
<li>least square problems</li>
<li>inner product spaces</li>
</ul>
<h3><b>8. Symmetric Matrices and Quadratic Forms</b></h3>
<p>A story about multi channel image processing is the introduction of chapter 8. This chapter has sections on quadratic forms and singular value decomposition.</p>
<p><br/></p>
<p>The book is very readable and entertaining. The diverse list of examples are already reason enough to recommend &#8220;Linear Algebra and Its Applications&#8221;. I give this book 5 stars out of 5.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F02%2F03%2Flinear-algebra-book-review&amp;title=Linear%20Algebra%20Book%20review" id="wpa2a_4"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/02/03/linear-algebra-book-review/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NumPy Project Euler Problem 5</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/02/01/numpy-project-euler-problem-5</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/02/01/numpy-project-euler-problem-5#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:44:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=254</guid>
		<description><![CDATA[Project Euler Problem 5is one of those problems that seem hard, but turn out to be trivial after you think about them. In this case it is very important to use the information given to you in the problem. This [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/problem=5">Project Euler Problem 5</a>is one of those problems that seem hard, but turn out to be trivial after you think about them. In this case it is very important to use the information given to you in the problem. This means using the fact that 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. We can therefore limit our search to multiples of 2520.</p>
<h3><strong>1. Create a divisors array</strong></h3>
<p>First we will create a divisors array. We only need to divide by the numbers 11 &#8211; 20.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">divisors = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">11</span>, <span style="color: #ff4500;">21</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>2. Check for 0 remainder</strong></h3>
<p>Second make sure that all the divisions of a number by the divisors produce a 0 remainder. We can check for that with the NumPy all function.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numpy.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> divisors<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>3. Test the solution</strong></h3>
<p>Eventually we will get an answer. We need to check whether this is the correct answer. Use the assert_equal function from the numpy.testing module to confirm the result.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">zeros</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">19</span><span style="color: black;">&#41;</span>, i <span style="color: #66cc66;">%</span> numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">21</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Below is the complete code solution.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy
&nbsp;
<span style="color: #808080; font-style: italic;">#2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># 1. Create a divisors array</span>
divisors = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">11</span>, <span style="color: #ff4500;">21</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2520</span>, <span style="color: #ff4500;">10</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">9</span>, <span style="color: #ff4500;">2520</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># 2. Check for 0 remainder</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> numpy.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> divisors<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">print</span> i
                <span style="color: #808080; font-style: italic;"># 3. Test the solution</span>
                numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">zeros</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">19</span><span style="color: black;">&#41;</span>, i <span style="color: #66cc66;">%</span> numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">21</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>

<p>&nbsp;</p>
<p>If you liked this post and are interested in NumPy check out <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy Beginner&#8217;s Guide</a> by yours truly. The <a href="http://ivanidris.net/wordpress/index.php/2011/12/23/christmas-numpy-book-giveaway">NumPy Christmas Book Giveaway</a> has officially ended. Winners will be contacted by the publisher. A new <a href="http://www.amazon.com/review/R2ZUZ5P6PN7T5Q/">review</a> of the book was added on Amazon.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F02%2F01%2Fnumpy-project-euler-problem-5&amp;title=NumPy%20Project%20Euler%20Problem%205" id="wpa2a_6"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/02/01/numpy-project-euler-problem-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[NumPy Project Euler]]></series:name>
	</item>
		<item>
		<title>Technical Career Navigator Review</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/29/technical-career-navigator-review</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/29/technical-career-navigator-review#comments</comments>
		<pubDate>Sun, 29 Jan 2012 10:55:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=252</guid>
		<description><![CDATA[In these hard economic times The Technical Career Navigator by Ray Weiss is the perfect book to help you find a job, keep your job and advance your career. The book is written for programmers, hardware engineers, technical managers and [...]]]></description>
			<content:encoded><![CDATA[<p>In these hard economic times The Technical Career Navigator by Ray Weiss is the perfect book to help you find a job, keep your job and advance your career. The book is written for programmers, hardware engineers, technical managers and documentation writers. It consists of two alphabetically sorted lists of one to three page articles. Each article starts with one or more relevant quotes. The first list contains general tips for the intended audience. The second list contains job search tips.</p>
<div align="center">
<a href="http://s724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/DSCN1859.jpg" rel="lightbox[technavigator]"><img src="http://i724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/th_DSCN1859.jpg" border="0" alt="Technical Navigator" ></a>
</div>
<table>
<tr>
<td><b>Author</b></td>
<td>Ray Weiss</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>013148396X</td>
</tr>
</table>
<p>I tried dividing the first list in some sublists for the purpose of this review.</p>
<h3><b>Career</b></h3>
<p>As expected the book contains a number of general career insights.</p>
<ul>
<li>Be Noticed &#8211; do your work and make sure you&#8217;re noticed. </li>
<li>Consulting &#8211; tips on avoiding doing grunt work, setting your rates, growing your skillset and finding new projects.</li>
<li>Decisions &#8211; we make so many decisions in our working life, that we need to review where we are heading at least once a year.</li>
<li>Hairy Arm &#8211; leave an obvious flaw in your design or proposal. People want to have something to fix before accepting your idea.</li>
<li>I don&#8217;t Know &#8211; it&#8217;s hard to say that you don&#8217;t know something, but it is the best thing to do.</li>
<li>Lateral Thinking &#8211; a different way to solve problems.</li>
<li>Line Versus Service &#8211; work where the money is, line organizations.</li>
</ul>
<h3><b>Product Marketing</b></h3>
<p>Surprisingly, the book also has advice on product marketing.</p>
<ul>
<li>Betting On Instinct &#8211; most companies do extensive market analysis, however eventually decisions are made not based on numbers, but intuition.</li>
<li>By The You-Know-Whats &#8211; this one doesn&#8217;t require any explanation.</li>
</ul>
<h3><b>Technical Management</b></h3>
<p>Technical management pitfalls are also discussed in the book.</p>
<ul>
<li>Breaking Owsie Chains &#8211; owsie chains are bad. You need to find a way to break them.</li>
<li>Consent of the Governed &#8211; managers do not have a Divine Right to rule.</li>
<li>Credit Theory of Management &#8211; this theory compares management to credit banking.</li>
<li>Fear &#8211; you cannot innovate if you live in fear.</li>
<li>Gearing up &#8211; shifting from mediocrity to superiority.</li>
<li>Hiring &#8211; a list of hiring techniques is given.</li>
<li>It&#8217;s not What you do &#8211; do not expect other people to work in the same way or at the same level as you do.</li>
</ul>
<h3><b>Writing and Documentation</b></h3>
<p>The author is a former technical editor with years of experience writing documentation.</p>
<ul>
<li>Conceptual Maps &#8211; needed for documentation. I wonder if <a href="http://en.wikipedia.org/wiki/Mind_map">mind maps</a> are meant here.</li>
<li>Learn to Write &#8211; writing can be learned. You need to read and practice a lot. There are two stages. First, aim for simplicity. In the last stage you try to perfect your style. For a technical writer content is more important than style.</li>
<li>Writing Memos, Letters &#8211; use a pyramidlike approach, put concepts at the top and details at the bottom. Use contractions and keep the text simple.</li>
</ul>
<h3><b>Programmer or Engineer</b></h3>
<p>The writer seems to make a distinction between programmers and hardware engineers.</p>
<ul>
<li>Design Reviews &#8211; reviews are needed to find errors early.</li>
<li>Engineering Notebook &#8211; you should have one, preferably a paper notebook.</li>
<li>Expecting Too Much &#8211; you don&#8217;t expect your code to work the first time you run it, do you? Why would it be different in real life?</li>
<li>Invest 30 minutes a Day &#8211; set time aside each day to keep current.</li>
<li>Pat Yourself on the Back &#8211; as you become more senior you will get less and less kudos from management. Know your worth.</li>
<li>Product Track Record &#8211; make sure you have some successes.</li>
</ul>
<h3><b>Job Search Tips</b></h3>
<p>At the end of the book we find hints and observations about job hunting.</p>
<ul>
<li>Catching a Horse &#8211; finding a job is easier, while you have one.</li>
<li>Contacting People &#8211; hints on contacting managers and recruiters.</li>
<li>Do It In Parallel &#8211; search in parallel fashion.</li>
</ul>
<p>Technical Career Navigator contains many hidden gems. It&#8217;s a book you will be reading again and again. I give this book 5 stars out of 5.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F29%2Ftechnical-career-navigator-review&amp;title=Technical%20Career%20Navigator%20Review" id="wpa2a_8"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/29/technical-career-navigator-review/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NumPy Project Euler Problem 4</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/25/numpy-project-euler-problem-4</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/25/numpy-project-euler-problem-4#comments</comments>
		<pubDate>Wed, 25 Jan 2012 20:58:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[euler]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=247</guid>
		<description><![CDATA[Project Euler Problem 4 is a bit silly. It&#8217;s about palindromic numbers. I could not find an appropriate algorithm, so I just tried something out. It seems to work OK.
1. Create a 3-digit numbers array
We will create an array to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/problem=4">Project Euler Problem 4</a> is a bit silly. It&#8217;s about palindromic numbers. I could not find an appropriate algorithm, so I just tried something out. It seems to work OK.</p>
<h3><strong>1. Create a 3-digit numbers array</strong></h3>
<p>We will create an array to hold 3-digit numbers from 100 to 999 using our favorite <a href="http://numpy.scipy.org/">NumPy</a> function arange. Check the first and last element of the array with the assert_equal function from the numpy.testing package.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span>, <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span>, a<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">999</span>, a<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>2. Create the products array</strong></h3>
<p>Now we will create an array to hold all the possible products of the elements of the 3-digits array with itself. We can accomplish this with the outer function. The resulting array needs to be flattened with ravel, to be able to easily iterate over it. Call the sort method on the array to make sure the array is properly sorted. After that we can do some sanity checks.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">numbers = numpy.<span style="color: black;">outer</span><span style="color: black;">&#40;</span>a, a<span style="color: black;">&#41;</span>
numbers = numpy.<span style="color: black;">ravel</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>
numbers.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">810000</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span>, numbers<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">998001</span>, numbers<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>3. Find the largest palindromic number</strong></h3>
<p>At this point I decided to continue with standard Python. We can probably do something fancy with NumPy, but it looked like reversing string representations of the numbers, and comparing them to the originals would be simpler.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
   s = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">if</span> s == s<span style="color: black;">&#91;</span>::-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>:
      <span style="color: #ff7700;font-weight:bold;">print</span> s
      <span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>

<p>Below is the complete program.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy
<span style="color: #ff7700;font-weight:bold;">import</span> numpy.<span style="color: black;">testing</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#A palindromic number reads the same both ways.</span>
<span style="color: #808080; font-style: italic;">#The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Find the largest palindrome made from the product of two 3-digit numbers.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#1. Create  3-digits numbers array</span>
a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span>, <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span>, a<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">999</span>, a<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#2. Create products array</span>
numbers = numpy.<span style="color: black;">outer</span><span style="color: black;">&#40;</span>a, a<span style="color: black;">&#41;</span>
numbers = numpy.<span style="color: black;">ravel</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>
numbers.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">810000</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span>, numbers<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
numpy.<span style="color: black;">testing</span>.<span style="color: black;">assert_equal</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">998001</span>, numbers<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#3. Find largest palindromic number</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#41;</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
   s = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>numbers<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">if</span> s == s<span style="color: black;">&#91;</span>::-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>:
      <span style="color: #ff7700;font-weight:bold;">print</span> s
      <span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>

<h3><strong>Have a Go</strong></h3>
<p>Although I am pretty sure this is the right solution, it might be a good idea to check the result. Find out which two 3-digit numbers produce our palindromic number by modifying the code a bit. Try implementing the last step in a NumPy way.</p>
<p>&nbsp;</p>
<p>If you liked this post and are interested in NumPy check out <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy Beginner&#8217;s Guide</a> by yours truly. I would like to make a few announcements. First, I was recently interviewed by <a href="http://www.floss4science.com/interview-ivan-idris-numpy-1-5-beginners-guide/">floss4science</a> about the book. Second, a gentle reminder that the <a href="http://ivanidris.net/wordpress/index.php/2011/12/23/christmas-numpy-book-giveaway">Christmas NumPy Book Giveaway</a> is going to end this month.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F25%2Fnumpy-project-euler-problem-4&amp;title=NumPy%20Project%20Euler%20Problem%204" id="wpa2a_10"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/25/numpy-project-euler-problem-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[NumPy Project Euler]]></series:name>
	</item>
		<item>
		<title>Refactoring Book Review</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/22/refactoring-book-review</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/22/refactoring-book-review#comments</comments>
		<pubDate>Sun, 22 Jan 2012 11:26:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=245</guid>
		<description><![CDATA[Refactoring is the process of rewriting software, without changing the way it functions, in order to improve its readability, testability or maintanability. A book has been written on the subject by Martin Fowler. Some of the chapters were written by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Code_refactoring">Refactoring</a> is the process of rewriting software, without changing the way it functions, in order to improve its readability, testability or maintanability. A book has been written on the subject by <a href="http://martinfowler.com/">Martin Fowler</a>. Some of the chapters were written by other people.</p>
<p>&#8220;Refactoring: Improving the Design of Existing Code&#8221; is focused on OO programming (lots of Java examples) and Agile practices. It is setup as a catalog of refactoring techniques. Each page dedicated to a refactoring is clearly marked, so that you can easily look up a refactoring.</p>
<p>The book was written a decade ago. At that time IDE&#8217;s did not support advanced refactorings. Most of the methods described are fully automated in modern IDE&#8217;s. This means that you don&#8217;t have to follow the text that closely any more.</p>
<div align="center">
<a href="http://s724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/DSCN1847.jpg" rel="lightbox[refactoring]"><img src="http://i724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/th_DSCN1847.jpg" border="0" alt="Refactoring Book" ></a>
</div>
<table>
<tr>
<td><b>Author</b></td>
<td>Martin Fowler, Kent Beck, John Brant and William Opdyke</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0201485672</td>
</tr>
</table>
<h3><b>1. Refactoring, a First Example</b></h3>
<p>The first chapter starts with a simple example. Java code is used throughout the example as well as UML diagrams.</p>
<h3><b>2. Principles in Refactoring</b></h3>
<p>The Why and When of refactoring are discussed. Also we get instructions on what to tell our manager about refactoring. This seems a bit silly to me, since I have never had to explain refactoring to my managers.</p>
<h3><b>3. Bad Smells in Code</b></h3>
<p>&#8220;Code Smells&#8221; is a frequently used Agile phrase. A phrase I don&#8217;t care that much about. Code works or it doesn&#8217;t, it can be ugly or unreadable, but it doesn&#8217;t smell. The list of &#8220;smells&#8221; makes sense, however some of the names are downright confusing. For instance, would you be able to tell me what &#8220;Refused Bequest&#8221; means?</p>
<h3><b>4. Building Tests</b></h3>
<p>This chapter talks about <a href="http://www.junit.org/">JUnit</a> at length. I am sure you are aware that there are many other unit testing frameworks for programming languages other than Java such as <a href="http://pyunit.sourceforge.net/">PyUnit</a>. We are told that before you start refactoring, you need to have tests. I think it is more of a chicken/egg dilemma. Sometimes you need to refactor first in order to test. Unit tests and functional tests are mentioned. Integration tests, however are completely ignored. How would you know whether the performance and memory usage of your system remained the same? Clearly, this chapter was written by a software developer, and not by somebody who likes breaking applications, I mean testing applications.</p>
<h3><b>5. Toward a Catalog of Refactorings</b></h3>
<p>Chapter 5 describes the catalog of refactorings to follow. It is the catalog metada in a sense.</p>
<h3><b>6. Composing methods</b></h3>
<p>This chapter is the beginning of the catalog, which forms the &#8220;meat&#8221; of the book. I am just going to mention a few of the techniques listed in chapter 6.&#8221;Extract Method&#8221; is one of those refactorings I use on a daily basis. Sometimes things go wrong so we have to do the opposite refactoring &#8220;Inline Method&#8221;. The author starts using the term &#8220;temp&#8221; to mean temporary local variables.</p>
<h3><b>7. Moving Features Between Objects</b></h3>
<p>The author admits that he has trouble assigning responsibilities to objects. We are supposed to fix errors with &#8220;Move Method&#8221;, &#8220;Move Field&#8221;, &#8220;Extract Class&#8221; or other refactorings in this chapter.</p>
<h3><b>8. Organizing Data</b></h3>
<p>This chapter discusses a lot of different ways to simplify working with data. For instance, with these refactorings:</p>
<ul>
<li>Replace Data Value with Object</li>
<li>Replace Array with Object</li>
</ul>
<p>Also the refactoring &#8220;Replace Magic Number with Symbolic Constant&#8221; is explained a.k.a &#8220;Extract Constant&#8221;.</p>
<h3><b>9. Simplifying Conditional Expressions</b></h3>
<p>In my opinion the refactorings in this chapter need to be renamed. Apart from &#8220;Decompose Conditional&#8221;, which is clear enough. Although &#8220;Breaking up Conditional&#8221; might have been better.</p>
<h3><b>10. Making Method Calls Simpler</b></h3>
<p>Make method calls simpler by renaming them or replacing long parameter lists by objects. The latter technique could be a problem in concurrent programs. It is common to pass immutable values as parameters. You might not be able to replace them by immutable objects.</p>
<h3><b>11. Dealing with Generalization</b></h3>
<p>Generalization or in OO terms inheritance is a powerful mechanism, that tends to be overused a lot. You can push/pull a method or a field. Inheritance can be replaced by delegation and vice versa.</p>
<h3><b>12. Big Refactorings</b></h3>
<p>In this chapter starts what we can call the &#8220;dessert&#8221; part. No more simple refactoring recipes. Instead four refactorings that take a considerable amount of time.</p>
<h3><b>13. Refactoring, Reuse and Reality</b></h3>
<p>This chapter is an essay on Refactoring by William Opdyke.</p>
<h3><b>14. Refactoring Tools</b></h3>
<p>IDE&#8217;s have come a long way since this book was written. Most of the issues in this chapter are no longer valid.</p>
<h3><b>15. Putting It All Together</b></h3>
<p>This final chapter by Kent Beck is a bit mystical and vague. Those are his own words by the way. Some of the points make sense, but the chapter is written too much in a master talking to an apprentice style.</p>
<p>The book has a list of soundbites at the end. Literally. The fun thing is that you probably have heard or are going to hear a lot of these soundbites. &#8220;Refactoring&#8221; is a very useful book, albeit too focused on Java. Most recipes would work for another Object Oriented language. I give this book 5 stars out of 5.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F22%2Frefactoring-book-review&amp;title=Refactoring%20Book%20Review" id="wpa2a_12"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/22/refactoring-book-review/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NumPy Project Euler Problem 3</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/19/numpy-project-euler-problem-3</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/19/numpy-project-euler-problem-3#comments</comments>
		<pubDate>Thu, 19 Jan 2012 21:18:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=241</guid>
		<description><![CDATA[Project Euler Problem 3 seems almost impossible to crack. However, using the right algorithm &#8211; Fermat&#8217;s factorization method and NumPy, it becomes very easy. The idea is to factor a number N into two numbers c and d.

   [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/problem=3">Project Euler Problem 3</a> seems almost impossible to crack. However, using the right algorithm &#8211; <a href="http://en.wikipedia.org/wiki/Fermat%27s_factorization_method">Fermat&#8217;s factorization method</a> and NumPy, it becomes very easy. The idea is to factor a number N into two numbers c and d.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">   N = c <span style="color: #66cc66;">*</span> d  = <span style="color: black;">&#40;</span>a + b<span style="color: black;">&#41;</span> <span style="color: black;">&#40;</span>a - b<span style="color: black;">&#41;</span> = a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> - b <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span></pre></div></div>

<p>We can apply the factorization recursively, until we get the required prime factors.</p>
<h3><strong>1. Create array of trial values</strong></h3>
<p>The algorithm requires us to try a number of trial values for <strong>a</strong>. It makes sense to create a NumPy array and eliminate the need for loops. However, you should be careful to not create an array that is too big. On my system an array of a million elements seems to be just the right size.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">   a = numpy.<span style="color: black;">ceil</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   lim = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>n, LIM<span style="color: black;">&#41;</span>
   a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span>a, a + lim<span style="color: black;">&#41;</span>
   b2 = a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> - n</pre></div></div>

<h3><strong>2. Get the fractional part of the b array</strong></h3>
<p>We are now supposed to check whether <strong>b</strong> is a square. Use the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.modf.html">NumPy modf function</a> to get the fractional part of the <strong>b</strong> array.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">   fractions = numpy.<span style="color: black;">modf</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span>b2<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></pre></div></div>

<h3><strong>3. Find 0 fractions</strong></h3>
<p>Call the NumPy where function to find the indices of 0 fractions.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">   indices = numpy.<span style="color: black;">where</span><span style="color: black;">&#40;</span>fractions == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<h3><strong>4. Find the first occurrence of a 0 fraction</strong></h3>
<p>Actually we only need the first occurrence of a 0 fraction. First, call the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.take.html">NumPy take function</a> with the indices array from the previous step to get the a values of 0 fractions. Now we need to &#8220;flatten&#8221; this array with the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html">NumPy ravel function</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">   a = numpy.<span style="color: black;">ravel</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">take</span><span style="color: black;">&#40;</span>a, indices<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Below is the entire code needed to solve the problem.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy
&nbsp;
<span style="color: #808080; font-style: italic;">#The prime factors of 13195 are 5, 7, 13 and 29.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#What is the largest prime factor of the number 600851475143 ?</span>
&nbsp;
N = <span style="color: #ff4500;">600851475143</span>
LIM = <span style="color: #ff4500;">10</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">6</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> factor<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
   <span style="color: #808080; font-style: italic;">#1. Create array of trial values</span>
   a = numpy.<span style="color: black;">ceil</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   lim = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>n, LIM<span style="color: black;">&#41;</span>
   a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span>a, a + lim<span style="color: black;">&#41;</span>
   b2 = a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> - n
&nbsp;
   <span style="color: #808080; font-style: italic;">#2. Check whether b is a square</span>
   fractions = numpy.<span style="color: black;">modf</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span>b2<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">#3. Find 0 fractions</span>
   indices = numpy.<span style="color: black;">where</span><span style="color: black;">&#40;</span>fractions == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">#4. Find the first occurrence of a 0 fraction</span>
   a = numpy.<span style="color: black;">ravel</span><span style="color: black;">&#40;</span>numpy.<span style="color: black;">take</span><span style="color: black;">&#40;</span>a, indices<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
   a = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
   b = numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span>a <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> - n<span style="color: black;">&#41;</span>
   b = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span>
   c = a + b
   d = a - b
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">if</span> c == <span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">or</span> d == <span style="color: #ff4500;">1</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">print</span> c, d
   factor<span style="color: black;">&#40;</span>c<span style="color: black;">&#41;</span>
   factor<span style="color: black;">&#40;</span>d<span style="color: black;">&#41;</span>
&nbsp;
factor<span style="color: black;">&#40;</span>N<span style="color: black;">&#41;</span></pre></div></div>

<p>The code prints the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff4500;">1234169</span> <span style="color: #ff4500;">486847</span>
<span style="color: #ff4500;">1471</span> <span style="color: #ff4500;">839</span>
<span style="color: #ff4500;">6857</span> <span style="color: #ff4500;">71</span></pre></div></div>

<h3><strong>Have a go</strong></h3>
<p>I would suggest writing an unit test to check the outcome. Use for example trial division. To get you started here is some of the code of a possible test function. Please fill in the dots.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> is_prime<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
   a = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, n<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#91;</span>...<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span></pre></div></div>

<p>Also maybe you should try finetuning the size of the trial values array, but be careful.</p>
<p>&nbsp;</p>
<p>If you liked this post and are interested in NumPy check out <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy Beginner&#8217;s Guide</a> by yours truly.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F19%2Fnumpy-project-euler-problem-3&amp;title=NumPy%20Project%20Euler%20Problem%203" id="wpa2a_14"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/19/numpy-project-euler-problem-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[NumPy Project Euler]]></series:name>
	</item>
		<item>
		<title>2 Beautiful Computer Graphics Books</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/15/2-beautiful-computer-graphics-books</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/15/2-beautiful-computer-graphics-books#comments</comments>
		<pubDate>Sun, 15 Jan 2012 13:02:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=239</guid>
		<description><![CDATA[These Computer Graphics books are beautiful, because they have lots of color plates and figures, hardcover with nice designs. I think you should appreciate these kind of things, otherwise you could just as well hold a stack of paper in [...]]]></description>
			<content:encoded><![CDATA[<p>These Computer Graphics books are beautiful, because they have lots of color plates and figures, hardcover with nice designs. I think you should appreciate these kind of things, otherwise you could just as well hold a stack of paper in your hands or read an ebook.</p>
<div align="center">
<a href="http://s724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/DSCN1803.jpg" rel="lightbox[2graphicsbooks]"><img src="http://i724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/th_DSCN1803.jpg" border="0" alt="Computer Graphics Books" ></a>
</div>
<h3><b>1. Interactive Computer Graphics: A Top-Down Approach With Opengl</b></h3>
<table>
<tr>
<td><b>Author</b></td>
<td>Edward Angel</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0201855712</td>
</tr>
</table>
<p>This is an introductory book about OpenGL. We had an optional course on OpenGL in University and this book was required reading for this course.</p>
<p>Chapter 1 introduces some basic concepts, such as camera models and ray tracing.</p>
<p>Chapter 2 gets us started wih the OpenGL API.</p>
<p>Chapter 3 discusses input devices, the client-server perspective and menus.</p>
<p>Chapter 4 starts with a bit of geometry and linear algebra. This is followed by an OpenGL example. The chapter ends with transformations supported by OpenGL.</p>
<p>Chapter 5 deals with projections and perspective.</p>
<p>Chapter 6 is about light, light sources, reflection and ray tracing.</p>
<p>Chapter 7 involves studying implementation algorithms for geometric transformations, clipping and rasterization.</p>
<p>Modeling the real world is the topic of Chapter 8. This includes physical models based on elementary Newtonian mechanics.</p>
<p>Chapter 9 teaches us about curves and splines.</p>
<p>Chapter 10 mentions texture mapping, bit and pixel operations, composition techniques, sampling and aliasing.</p>
<p>The chapter titles could have been a bit longer and more descriptive. The book goes over some  mathematics and theory. However, it never gets very challenging. I would not buy the book for that. There are lots of OpenGL examples. This is the strength of the book. Although the book has color plates and a nice hard cover, the code does not have syntax highlighting. You might say that I am too used to IDE&#8217;s, but I have seen syntax highlighting in at least one book, so it should be possible. I give this book 3 stars out of 5.</p>
<h3><b>2. Computer Graphics: Principles and Practice in C (2nd Edition)</b></h3>
<table>
<tr>
<td><b>Author</b></td>
<td>James D. Foley, Andries van Dam, Steven K. Feiner and John F. Hughes</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0201848406</td>
</tr>
</table>
<p>Computer Graphics is about computer graphics and principles. This book has four authors, who are experts in their field. It has a hardcover, is richly illustrated with color plates and lots of figures. If the code had syntax highlighting, then it would have been even better.</p>
<p>Chapter 1 covers the basics. Chapter 2 is about SGRP (Simple Raster Graphics Package). Chapter 3 presents basic raster graphics algorithms for drawing 2D primitives.</p>
<p>Chapter 4 describes graphics hardware. Chapter 5 introduces geometrical transformations. Chapter 6 discusses viewing in 3D, projections and perspective.</p>
<p>Chapter 7 is dedicated to SPHIGS (Simple Programmer&#8217;s Hierarchical Interactive Graphics System). Chapter 8 is the first of three chapters on GUI&#8217;s. These three chapters are low on mathematics and code. Dialogue design is the title of Chapter 9. Chapter 10 examines user interface software.</p>
<p>Chapter 11 is about representing curves and surfaces. Finally, we get back to some code and mathematics. Chapter 12 builds on the previous chapter and continues with solid modeling. Sadly, no code in this chapter. Achromatic and colored light is the subject of chapter 13. This is a fun chapter, however, the lack of color usage in this chapter about color seems paradoxical to me.</p>
<p>In Chapter 14 we embark on a quest for visual realism. Chapter 15 is about visible-surface determination. Chapter 16 discusses illumination and shading.</p>
<p>Chapter 17 explores image manipulation and storage. Chapter 18 discusses advanced raster graphics architecture. Chapter 19 describes advanced geometric and raster algorithms.</p>
<p>Chapter 20 concentrates on advanced modeling techniques. Chapter 21 brings to life animation.</p>
<p>As I said above, this book is written by four authors. Obviously, this means that the writing style differs between chapters. Some chapters have no code or mathematics. Some chapters have one or the other. These are not my favorite chapters. The code examples are written in C or sometimes in pseudocode that looks a lot like C, so you need to have some knowledge of C.</p>
<p>The book is quite thorough and seems pedagogically sound. It is considered a &#8220;classic&#8221; for many reasons. Personally, I learned a lot about computer graphics algorithms. I give this book 4 stars out of 5.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F15%2F2-beautiful-computer-graphics-books&amp;title=2%20Beautiful%20Computer%20Graphics%20Books" id="wpa2a_16"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/15/2-beautiful-computer-graphics-books/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NumPy Project Euler Problem 2</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/12/numpy-project-euler-problem-2</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/12/numpy-project-euler-problem-2#comments</comments>
		<pubDate>Thu, 12 Jan 2012 12:21:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=236</guid>
		<description><![CDATA[Project Euler Problem 2 is definitely harder than Problem 1. This one requires reading the Fibonacci numbers Wikipedia article.
I read that the Project Euler problems are some sort of katas. Katas are what martial artist call exercises, preparing you for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://projecteuler.net/problem=2">Project Euler Problem 2</a> is definitely harder than <a href="http://ivanidris.net/wordpress/index.php/2012/01/07/numpy-project-euler-problem-1">Problem 1</a>. This one requires reading the <a href="http://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci numbers Wikipedia article</a>.</p>
<p>I read that the Project Euler problems are some sort of katas. Katas are what martial artist call exercises, preparing you for real-life fighting situations. For instance, imagine that your house is on fire and that your family is surrounded by heavily armed thugs. What do you do? In this case your secret weapon is <a href="http://numpy.scipy.org/">NumPy</a>, which is like the <a href="http://en.wikipedia.org/wiki/Touch_of_Death">Dim Mak death touch</a>. If you master that like me, then you don&#8217;t even need to bother with katas.</p>
<h3><b>1. Calculate the golden ratio</b></h3>
<p>When the bad ninja guys are walking towards you, the first thing to do, is calculate the <a href="http://en.wikipedia.org/wiki/Golden_ratio">golden ratio</a>, also called the golden section. This part of the kata is called Moro Ashi Dachi.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">phi = <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> + numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Phi&quot;</span>, phi</pre></td></tr></table></div>

<p>This prints the golden mean.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">Phi <span style="color: #ff4500;">1.61803398875</span></pre></td></tr></table></div>

<h3><b>2. Find the index below 4 million</b></h3>
<p>Next in the kata we need to find the index below 4 million. A formula for this is given in the Wikipedia page. All we need to do is convert log bases. We don&#8217;t need to round the result down to the closest integer. This is automatically done for us in the next step of the kata.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">n = numpy.<span style="color: black;">log</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">10</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">6</span> <span style="color: #66cc66;">*</span> numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span>/numpy.<span style="color: black;">log</span><span style="color: black;">&#40;</span>phi<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> n</pre></td></tr></table></div>

<p>We get the result 33.2629480359. You can double check this yourself from the Wikipedia article.</p>
<h3><b>3. Create an array of 1-n </b></h3>
<p>No, you say. Not the arange function again. We know about it already, when are we going to learn about the Jyutping. Patience, let&#8217;s first master the basics.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">n = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, n<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<h3><b>4. Compute Fibonacci numbers</b></h3>
<p>There is a convenient formula we can use to calculate the Fibonacci numbers. We will need the golden ratio and the array from the previous step in the kata as input parameters. Print the first 9 Fibonaci numbers to check the result. I could have made an unit test instead of a print statement. This variation of the kata is left as an exercise for the reader.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">fib = <span style="color: black;">&#40;</span>phi<span style="color: #66cc66;">**</span>n - <span style="color: black;">&#40;</span>-<span style="color: #ff4500;">1</span>/phi<span style="color: black;">&#41;</span><span style="color: #66cc66;">**</span>n<span style="color: black;">&#41;</span>/numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;First 9 Fibonacci Numbers&quot;</span>, fib<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span></pre></td></tr></table></div>

<p>The output is below. You can plug this right into an unit test, if you want.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">First <span style="color: #ff4500;">9</span> Fibonacci Numbers <span style="color: black;">&#91;</span>  <span style="color: #ff4500;">1</span>.   <span style="color: #ff4500;">1</span>.   <span style="color: #ff4500;">2</span>.   <span style="color: #ff4500;">3</span>.   <span style="color: #ff4500;">5</span>.   <span style="color: #ff4500;">8</span>.  <span style="color: #ff4500;">13</span>.  <span style="color: #ff4500;">21</span>.  <span style="color: #ff4500;">34</span>.<span style="color: black;">&#93;</span></pre></td></tr></table></div>

<h3><b>5. Convert to integers</b></h3>
<p>This step is optional. I think it&#8217;s nice to have an integer result at the end. It&#8217;s like the difference between Mawashi Geri and Mawashi Geri Koshi. The effect is almost the same, but one feels better than the other. OK, I actually wanted to show you the astype function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">fib = fib.<span style="color: black;">astype</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Integers&quot;</span>, fib</pre></td></tr></table></div>

<p>A long list of numbers is printed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">Integers <span style="color: black;">&#91;</span>      <span style="color: #ff4500;">1</span>       <span style="color: #ff4500;">1</span>       <span style="color: #ff4500;">2</span>       <span style="color: #ff4500;">3</span>       <span style="color: #ff4500;">5</span>       <span style="color: #ff4500;">8</span>      <span style="color: #ff4500;">13</span>      <span style="color: #ff4500;">21</span>      <span style="color: #ff4500;">34</span>
  ... <span style="color: black;">snip</span> ... <span style="color: black;">snip</span> ...
  <span style="color: #ff4500;">317811</span>  <span style="color: #ff4500;">514229</span>  <span style="color: #ff4500;">832040</span> <span style="color: #ff4500;">1346269</span> <span style="color: #ff4500;">2178309</span> <span style="color: #ff4500;">3524578</span><span style="color: black;">&#93;</span></pre></td></tr></table></div>

<h3><b>6. Select even-valued terms</b></h3>
<p>The kata demands that we select the even valued terms now. This should be easy for you, if you followed the <a href="http://ivanidris.net/wordpress/index.php/2012/01/07/numpy-project-euler-problem-1">previous kata</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">eventerms = fib<span style="color: black;">&#91;</span>fib <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">2</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> eventerms</pre></td></tr></table></div>

<p>There we go. Another opportunity to write unit tests.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span>      <span style="color: #ff4500;">2</span>       <span style="color: #ff4500;">8</span>      <span style="color: #ff4500;">34</span>     <span style="color: #ff4500;">144</span>     <span style="color: #ff4500;">610</span>    <span style="color: #ff4500;">2584</span>   <span style="color: #ff4500;">10946</span>   <span style="color: #ff4500;">46368</span>  <span style="color: #ff4500;">196418</span>
  <span style="color: #ff4500;">832040</span> <span style="color: #ff4500;">3524578</span><span style="color: black;">&#93;</span></pre></td></tr></table></div>

<h3><b>7. Sum the selected terms</b></h3>
<p>This is the final step. Your enemies are lying on the ground helpless, unable to fight back. Finish the job, call the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html">ndarray</a> sum method.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> eventerms.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>For completeness, below is the complete code of this kata.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> numpy
&nbsp;
<span style="color: #808080; font-style: italic;">#Each new term in the Fibonacci sequence is generated by adding the previous two terms. </span>
<span style="color: #808080; font-style: italic;">#By starting with 1 and 2, the first 10 terms will be:</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#By considering the terms in the Fibonacci sequence whose values do not exceed four million, </span>
<span style="color: #808080; font-style: italic;">#find the sum of the even-valued terms.</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#1. Calculate phi</span>
phi = <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> + numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Phi&quot;</span>, phi
&nbsp;
<span style="color: #808080; font-style: italic;">#2. Find the index below 4 million</span>
n = numpy.<span style="color: black;">log</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">10</span> <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">6</span> <span style="color: #66cc66;">*</span> numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">0.5</span><span style="color: black;">&#41;</span>/numpy.<span style="color: black;">log</span><span style="color: black;">&#40;</span>phi<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> n
&nbsp;
<span style="color: #808080; font-style: italic;">#3. Create an array of 1-n</span>
n = numpy.<span style="color: black;">arange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, n<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> n
&nbsp;
<span style="color: #808080; font-style: italic;">#4. Compute Fibonacci numbers</span>
fib = <span style="color: black;">&#40;</span>phi<span style="color: #66cc66;">**</span>n - <span style="color: black;">&#40;</span>-<span style="color: #ff4500;">1</span>/phi<span style="color: black;">&#41;</span><span style="color: #66cc66;">**</span>n<span style="color: black;">&#41;</span>/numpy.<span style="color: black;">sqrt</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;First 9 Fibonacci Numbers&quot;</span>, fib<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#5. Convert to integers</span>
<span style="color: #808080; font-style: italic;"># optional</span>
fib = fib.<span style="color: black;">astype</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Integers&quot;</span>, fib
&nbsp;
<span style="color: #808080; font-style: italic;">#6. Select even-valued terms</span>
eventerms = fib<span style="color: black;">&#91;</span>fib <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">2</span> == <span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> eventerms
&nbsp;
<span style="color: #808080; font-style: italic;">#7. Sum the selected terms</span>
<span style="color: #ff7700;font-weight:bold;">print</span> eventerms.<span style="color: #008000;">sum</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>That was quite a workout. More katas to come soon. Please stay tuned.</p>
<p><br/></p>
<p>If you liked this post and are interested in NumPy check out <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy Beginner&#8217;s Guide</a> by yours truly. I would like to thank <a title="On the DSP related blog" href="http://www.dsprelated.com/showarticle/157.php">Christopher Felton</a> and <a title="Gael Varoquaux" href="http://gael-varoquaux.info/blog/?p=161">Gael Varoquaux</a> for their recent reviews of my book.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F12%2Fnumpy-project-euler-problem-2&amp;title=NumPy%20Project%20Euler%20Problem%202" id="wpa2a_18"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/12/numpy-project-euler-problem-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[NumPy Project Euler]]></series:name>
	</item>
		<item>
		<title>3 Great Computer Science Books in My Library</title>
		<link>http://ivanidris.net/wordpress/index.php/2012/01/09/3-great-computer-science-books-in-my-library</link>
		<comments>http://ivanidris.net/wordpress/index.php/2012/01/09/3-great-computer-science-books-in-my-library#comments</comments>
		<pubDate>Mon, 09 Jan 2012 19:03:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[books]]></category>

		<guid isPermaLink="false">http://ivanidris.net/wordpress/?p=234</guid>
		<description><![CDATA[Here are 3 amazing (if a bit old) Computer Science books from my library.



1. TCP/IP Illustrated Volume 1


Author
W. Richard Stevens


ISBN-10
0201633469


This is a fantastic textbook about different network protocols. The protocols are illustrated using the output of tcpdump and other utilities. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are 3 amazing (if a bit old) Computer Science books from my library.</p>
<div align="center">
<a href="http://s724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/DSCN1798.jpg" rel="lightbox[3csbooks]"><img src="http://i724.photobucket.com/albums/ww242/ivanidris/numpyBeginnersGuide/th_DSCN1798.jpg" border="0" alt="3 CS Books" ></a>
</div>
<h3><b>1. TCP/IP Illustrated Volume 1</b></h3>
<table>
<tr>
<td><b>Author</b></td>
<td>W. Richard Stevens</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0201633469</td>
</tr>
</table>
<p>This is a fantastic textbook about different network protocols. The protocols are illustrated using the output of tcpdump and other utilities. Protocols discussed include:</p>
<ul>
<li>IP</li>
<li>ARP</li>
<li>RARP</li>
<li>ICMP</li>
<li>UDP</li>
<li>IGMP</li>
<li>TFTP</li>
<li>BOOTP</li>
<li>TCP</li>
<li>SNMP</li>
<li>FTP</li>
<li>SMTP</li>
</ul>
<p>Beside the protocols several diagnostic tools such as ping and traceroute are covered in detail. The book contains lots of diagrams, that illustrate the protocols even further. Each chapter ends with exercises. The solutions of some of those exercises can be found in the book as well. I give this book 4 stars out of 5.</p>
<h3><b>2. Database System Concepts</b></h3>
<table>
<tr>
<td><b>Authors</b></td>
<td>Abraham Silberschatz, Henry Korth, S. Sudarshan</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0071122680</td>
</tr>
</table>
<p>This book teaches about the inner workings, the nuts and bolts of databases without requiring a lot of prior knowledge:</p>
<ul>
<li>Data Models</li>
<li>Relational Databases</li>
<li>Object Based Databases and XML</li>
<li>Data Storage and Querying</li>
<li>Transaction Management</li>
<li>Database System Architecture</li>
</ul>
<p>Personally I feel that some material doesn&#8217;t belong here, such as XML, but it seems to be a tradition to include it. I found the chapter on indices quite interesting.</p>
<p>At the end of the book there are several chapters on popular commercial databases. It seems that these chapters do not add any value. In any case the authors should have devoted at least one chapter to an open source database. In the real world you have as much chance to work with a commercial database as with an open source one.</p>
<p>My copy is quite outdated by now. New developments, for instance NoSQL databases, are not mentioned. I give this book 3 out of 5 stars.</p>
<h3><b>3. Machine Learning</b></h3>
<table>
<tr>
<td><b>Author</b></td>
<td>Tom Mitchell</td>
</tr>
<tr>
<td><b>ISBN-10</b></td>
<td>0071154671</td>
</tr>
</table>
<p>This is an introductory book on Machine Learning. There is quite a lot of mathematics and statistics in the book, which I like. A large number of methods and algorithms are introduced:</p>
<ul>
<li>Neural Networks</li>
<li>Bayesian Learning</li>
<li>Genetic Algorithms</li>
<li>Reinforcement Learning</li>
</ul>
<p>The material covered is very interesting and clearly explained. I find the presentation, however, a bit lacking. I think it has to do with the chosen fonts and lack of highlighting of important terms. Maybe it would have been better to have shorter paragraphs too.</p>
<p>If you are looking for an introductory book on machine learning right now, I would not recommend this book, because in recent years better books have been written on the subject. These are better obviously, because they include coverage of more modern techniques. I give this book 3 out of 5 stars.</p>
<p><br/></p>
<hr/>
<p>Thanks for the <a href="http://www.packtpub.com/numpy-1-5-using-real-world-examples-beginners-guide/book">NumPy 1.5 Beginner&#8217;s Guide</a> review by <a href="http://fonnesbeck.calepin.co/review-numpy-15-beginners-guide/" title="On the Strong Inference Blog">Chris Fonnesbeck on the Strong Inference Blog</a>. </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fivanidris.net%2Fwordpress%2Findex.php%2F2012%2F01%2F09%2F3-great-computer-science-books-in-my-library&amp;title=3%20Great%20Computer%20Science%20Books%20in%20My%20Library" id="wpa2a_20"><img src="http://ivanidris.net/wordpress/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://ivanidris.net/wordpress/index.php/2012/01/09/3-great-computer-science-books-in-my-library/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

