NumPy Numpty — Data point #5

Whats a Numpty?

A numpty is defined by Cambridge University as a “stupid or silly person” and is how I feel when learning new technologies. I don’t mean to sound harsh, but to make a joke out of myself when trying to learn new things. For me, I have had to learn a lot of new technologies for my capstone including, sqlite3, HDF5 file format and thus h5py, NumPy, and more. All of which I have never touched.

Whats a NumPy?

Official Definition

NumPy is self described as, “…the fundamental package for scientific computing in Python. It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.”

And to be honest I didn’t really read that either, in fact I almost fell asleep during it. So… what does that giant block of text that someone way smarter than me wrote mean? First let’s look at the Python Language.

Interpreting Snakes

When I was a kid living in Virginia they explained the difference between Coral and Milk snakes who have the same colors. One is poisonous and one isn’t… they taught kids a rhyme, I can’t remember it; I just tended to avoid all snakes. Anyway, remembering interpretation vs. compilation is a lot like that when you are starting out as a programmer. You don’t exactly know whats different under the hood, but you know that you’re avoiding coding by using ChatGPT… just kidding ;), they didn’t have that when I started. But why do we need to compile some languages and not others? Well, compiled languages take what you have coded and turn it into machine code – compilers are built by really smart people. The machine code runs at lightning speed compared to interpreted languages which execute each command line by line. Compilers also help by reducing logic, where as interpreters don’t. In short, compilers take your code and reduce it to its best in machine code, and interpreted languages execute exactly what you code, no matter how good or bad. Python is the latter, interpreted (poisonous to speed). But it is very readable and writable.

The Numpty Definition of NumPy

Now please know that I’m definitely not calling anyone stupid, its more just fun alliteration to say that it IS okay to not know things and be bad at them when you are learning them, or you wouldn’t have to learn them!! So heres how I describe it:

NumPy is a Python library that is really just a Python wrapper around C (which is a compiled language) used for declaring and manipulating arrays in fancy ways. It allows the readability and writability of Python and the speed of C to come together.

Personal Experience using NumPy

I had never used NumPy before, I only heard it talked about and seen it put on job descriptions. It quickly has become a favorite library of mine and enjoy its ease of use. For example, my team needed a development tool to convert a sqlite file to an hdf5 file, but the SQL file was in rows and we needed to process by column. After lots of bad iterations involving lots of arrays being sliced and put back together and such I then found a way to do it with NumPy that was only a few lines of code and considerably faster than anything I could have come up with. First I got the SQL rows in a variable traces. Then I made that variable a NumPy array with np_traces = numpy.array(traces). After that, and this is the magic, I used numpy.stack(np_traces, axis=-1) and tada! – column order. After that the processing was easy.

New Tools

So, when you are learning new tools remember to give yourself grace and struggle with it, once you start to get it, it will be all the more rewarding, especially more rewarding than using ChatGPT haha. And if you come across a red, black, and yellow snake in the South remember, “Red touches black, friend of Jack. Red touches yellow, kill a fellow.” — I looked it up :).

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *