<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ben Pang on Medium]]></title>
        <description><![CDATA[Stories by Ben Pang on Medium]]></description>
        <link>https://medium.com/@benpang?source=rss-17633aaa0c50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*s77_5SVq5WuTPT2GBHzUzg.png</url>
            <title>Stories by Ben Pang on Medium</title>
            <link>https://medium.com/@benpang?source=rss-17633aaa0c50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:03:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benpang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tutorial: 1D Matrix Representation]]></title>
            <link>https://medium.com/@benpang/tutorial-1d-matrix-representation-5e660aa93696?source=rss-17633aaa0c50------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e660aa93696</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-tips]]></category>
            <dc:creator><![CDATA[Ben Pang]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 20:16:04 GMT</pubDate>
            <atom:updated>2019-09-23T11:14:00.327Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXGU-OcXOfbATpfpNKTcmA.jpeg" /><figcaption>Not the kind of matrix we’ll be talking about, but close enough.</figcaption></figure><p><em>This tutorial is aimed at beginners with basic programming knowledge. We’ll be using Python, but the concepts apply to most other conventional languages.</em></p><p>If you’ve done programming and/or math, you may have run into matrices. The common way that most people learn to implement matrices is below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e3718b86b156003bbf619475b92f251/href">https://medium.com/media/6e3718b86b156003bbf619475b92f251/href</a></iframe><p>This is an intuitive description of what the matrix is: a 2-dimensional “list” with rows and columns. To get an item from the matrix, we would simply do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90cae40945ebd0cdf52dee1f17188bd6/href">https://medium.com/media/90cae40945ebd0cdf52dee1f17188bd6/href</a></iframe><p>And to print the matrix, we could do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1570f63eccf80e5a3255d336f8ca2aea/href">https://medium.com/media/1570f63eccf80e5a3255d336f8ca2aea/href</a></iframe><p>Or if we wanted a string representation instead:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7c394fc882390615191fe91ea95a198/href">https://medium.com/media/d7c394fc882390615191fe91ea95a198/href</a></iframe><p>But what if we wanted to iterate through all items in the matrix and add 1 to each item?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f779ecd4f082cfe140d442b64062843/href">https://medium.com/media/2f779ecd4f082cfe140d442b64062843/href</a></iframe><p>Or what if we wanted to change the dimensions of the matrix?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b150e1dbb5d364a3f099742e917d23ec/href">https://medium.com/media/b150e1dbb5d364a3f099742e917d23ec/href</a></iframe><p>Now these probably don’t look too bad, but we appear to be limited by our 2D matrix representation. In fact, there <em>is</em> another way to represent the matrix to make the above tasks a bit easier.</p><h3>The Alternative</h3><p>Notice in the previous code for changing dimensions, we had a variable temp. Let’s take a closer look at the relevant portion of the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ca48ee413bf6c36464056476f1a161d/href">https://medium.com/media/0ca48ee413bf6c36464056476f1a161d/href</a></iframe><p>temp now contains a flattened version of our matrix, which is later used as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28d11aaced8ad667ab08eef935a7f80f/href">https://medium.com/media/28d11aaced8ad667ab08eef935a7f80f/href</a></iframe><p>Hmmm… so what if we just made temp our default matrix representation?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/965859a09eb7a4d3fd37cd37a3520129/href">https://medium.com/media/965859a09eb7a4d3fd37cd37a3520129/href</a></iframe><p>To get items from this matrix:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea75e0affc6a535569833c3a38d1ae50/href">https://medium.com/media/ea75e0affc6a535569833c3a38d1ae50/href</a></iframe><p>This might seem confusing at first, so let’s do an example. If we wanted to get the item at row 2 column 1 (0-indexed), mget would convert that row-column pair to 2 * cols + 1 =&gt; 2 * 3 + 1 =&gt; 7. The item at index 7 (0-indexed) of our odd matrix is 8. Understanding how mget works might take a bit of visualization, so try testing other row-column pairs to see how the r * cols + c formula works.</p><p>The immediately evident benefit of our new matrix representation can be seen in our new-and-improved code to add 1 to each item:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3035a82900e4399814c6458975ae3a7/href">https://medium.com/media/b3035a82900e4399814c6458975ae3a7/href</a></iframe><p>And our new-and-improved matrix reshaper:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/757b59bff3ba43bfc35b803f64c26407/href">https://medium.com/media/757b59bff3ba43bfc35b803f64c26407/href</a></iframe><p>The trick here is that the matrix representation on its own is just a 1D list. By adding rows and cols , however, we give this 1D list “dimensions.”</p><p>To print the matrix:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a09c1143b519df020f9e0f2a35b51f7/href">https://medium.com/media/6a09c1143b519df020f9e0f2a35b51f7/href</a></iframe><p>Note that i and not i % cols — 1 is equivalent to i &gt; 0 and i % cols = cols — 1 . Evidently, printing is not quite as straightforward in our new matrix representation.</p><p>To get a string representation of the matrix:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8a3393ed11ed135bc2b090075b831f4/href">https://medium.com/media/e8a3393ed11ed135bc2b090075b831f4/href</a></iframe><p>Quite a handful to type! But all we’re really doing is creating chunks of rows and joining them together with a space, then joining the chunks with newlines.</p><p>Now what if we want to make our matrix representation 2D like before?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ec693cc057ac45b068601f0334b6c09/href">https://medium.com/media/8ec693cc057ac45b068601f0334b6c09/href</a></iframe><p>We’re using the chunking idea from the string representation snippet to create the rows.</p><p>Some other cool things you can do include getting the diagonal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6ae5eccd81e7cb6a1861c3406acc520/href">https://medium.com/media/d6ae5eccd81e7cb6a1861c3406acc520/href</a></iframe><p>And, by extension, generating an identity matrix:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a18c7650a669a4f591ddffde68a401b/href">https://medium.com/media/9a18c7650a669a4f591ddffde68a401b/href</a></iframe><h3>Conclusion</h3><p>The “conventional” matrix representation is cool and intuitive, but our alternative matrix representation is way more stylish. Of course, each representation has its own benefits and drawbacks, but I think that it’s worth experimenting with to see which representation is best used in which cases.</p><p>May your code be clean and your programs bug-free.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e660aa93696" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memorizing the Geologic Time Scale]]></title>
            <link>https://medium.com/@benpang/memorizing-the-geologic-time-scale-4683c9afc50d?source=rss-17633aaa0c50------2</link>
            <guid isPermaLink="false">https://medium.com/p/4683c9afc50d</guid>
            <category><![CDATA[science]]></category>
            <category><![CDATA[geology]]></category>
            <category><![CDATA[earth]]></category>
            <category><![CDATA[memories]]></category>
            <category><![CDATA[biology]]></category>
            <dc:creator><![CDATA[Ben Pang]]></dc:creator>
            <pubDate>Thu, 20 Oct 2016 03:31:36 GMT</pubDate>
            <atom:updated>2016-10-20T03:32:09.789Z</atom:updated>
            <content:encoded><![CDATA[<p>Well, this is my first Medium article. I must say, Medium, kudos to you: this site’s really well-made.</p><p>Anyway, time to talk about the geologic time scale. One day, I decided to memorize Earth’s milestones. Don’t ask me why, I did it on a whim that may or may not have been related to APES.</p><p>Here’s the image I first used for reference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*nRuktqbcXYHMEh9Lxri1zA.gif" /></figure><p>For me, memorizing the geologic time scale meant not only remembering the order of each item in the time scale, but also remembering what happened in each item. As you will see, this actually works out in our favor.</p><p>So, let’s start!</p><h3>Eons</h3><p>Alrighty, this is the easy part. We have the Precambrian, which has 3 eons (Priscoan, Archaean, and Proterozoic) and Phanerozoic. I simply rote-memorized the Precambrian and Phanerozoic, then moved on to the Precambrian eons.</p><ul><li><strong>Priscoan: </strong>This is a bit hard to remember as is. Some cursory research revealed that this can also be called the Hadean eon, which is much better. At the time, Earth was in a solid/molten state and was constantly bombarded by asteroids. This made “Hadean” very connectable to “Hades,” or the underworld.</li><li><strong>Archaean:</strong> The eon when very primitive life-forms appear (ex.: <strong>archae</strong>bacteria). Given that I knew about archaebacteria, this was basically effortless.</li><li><strong>Proterozoic:</strong> During this eon, eukaryotes and multicellular organisms appeared. Given that this came right before the Phanerozoic, I just linked the two eons together through the “-zoic” suffix and memorized the beginning part.</li></ul><h3>Eras</h3><p>Now for the Phanerozoic eras: Paleozoic, Mesozoic, and Cenozoic. Good thing that they all end in “-zoic” and the prefixes are super-easy (“paleo” is “ancient,” “meso” is “middle,” and “ceno” is “recent”).</p><h3>Periods</h3><p>First, the Paleozoic:</p><ul><li><strong>Cambrian:</strong> The fact that this came after the Pre<strong>cambrian</strong> made this really easy to memorize. During this period, Earth experienced a massive increase in biodiversity known as the “Cambrian Explosion.”</li><li><strong>Ordovician:</strong> This was a when aquatic life began taking hold. I rote-memorized this, but the word itself had an interesting pronunciation.</li><li><strong>Silurian:</strong> Life starts moving to land, and plants form. For some reason, the word reminded me of soil or “<strong>sil</strong>t” — now here’s a connection to plants!</li><li><strong>Devonian:</strong> The so-called “Age of Fish” saw a significant <strong>dev</strong>elopment in both aquatic and terrestrial species.</li><li><strong>Carboniferous:</strong> Earth becomes much warmer and <strong>coal</strong> swamps form.</li><li><strong>Permian:</strong> At the end of the Permian, a spectacular event known as the “Great Dying” wiped out around 95% of the marine species. I remembered this as <em>“What could have been a </em><strong><em>perm</em></strong><em>anent growth in biodiversity was ruined by this mass extinction.”</em></li></ul><p>The Mesozoic periods (Triassic, Jurassic, Cretaceous) were basically already memorized since elementary school because of my extensive fascination with dinosaurs during that time. It is widely accepted that an asteroid impact in the Yucatan peninsula ended the Cretaceous period and brought about the end of the dinosaurs.</p><p>Finally, the Cenozoic. All of these ended in “-cene,” so I only needed to remember the prefixes:</p><ul><li><strong>Paleo:</strong> Mammals begin to increase in numbers. This is the <strong>old</strong>est of the Cenozoic periods.</li><li><strong>Eo:</strong> Basically the only time when birds dominated Earth. I pictured an eagle screeching “EO!” when memorizing this.</li><li><strong>Oligo:</strong> Grasslands start forming, which gives rise to grazing animals. Apparently, “oligo” (“few”) is a reference to the scarcity of mollusks at the time.</li><li><strong>Mio:</strong> This is when primates first appear. I just rote-memorized this.</li><li><strong>Plio:</strong> The Earth is simply cooler than it was previously. Again, rote-memory.</li><li><strong>Pleisto:</strong> This is the Ice Age with wooly mammoths and saber-toothed tigers! I mixed rote memory and the fact that it sounded like “Plio” but with an extra syllable.</li><li><strong>Holo:</strong> The modern age where humans dominate Earth, includes pretty much all of written human history. This one just stuck right when I saw it for some reason.</li></ul><p>And that’s it! It took a bit less than an hour. I haven’t started memorizing the dates yet, but that’s really the easy part.</p><p>Now you may be asking, “What’s the point? How is this good for anything?” Well, learning about these periods really puts everything into perspective: the evolution of life from archaebacteria to humans, the various mass extinctions that remodeled the entire Earth’s landscape, the temperature fluctuations throughout, the rearrangement of continents, and so on. By forcing myself to memorize the geologic time scale, I learned much more about Earth itself than I thought I ever would.</p><p>Of course, I may or may not have done this to study for APES.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4683c9afc50d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>