2019-08-06 22:29:30.643741

What's up stalkers welcome to day 13/14

Honestly sometimes I don't get this blog post out because I'm coding so hard.

In reality it's because I'm either watching too much Fortnite streams or playing Fortnite or neither of those and something else equally unproductive and by the time I feel like I should write this blog post it's about 4 am and the though of writing actually makes me physically tired enough that I would rather brush my teeth to prepare for bed.

Crazy.

It happens though. Here's a recap of yesterday:

Day 13

Yesterday I started digging into dataquest a bit more and I started some missions on the python data science library numPy. I've heard people (not in real life because I have no data science friends in real life but in youtube python data/programming conf talks (conf is short for conference get with it already stalker)) pronounce it "Num - Pie" but I honestly prefer "NUMPEEE" because it's hilarious and also I feel like I'm disrespecting absolutely no one by pronouncing like that. And did I mention it's hilarious?

In [1]:
import numpy

I'll get into what it does later but if you notice, from day 12 to yesterday there is no error when I import it. That's because I uninstalled every facet of the Anaconda distribution from my system and reinstalled it and now it works like a charm.

A majority of the programming I did yesterday was actually for my freelance gig. Job. Thing. I don't know. I use Selenium ( a web browser automation library ) to help pick up the pace of some of the tests I have to run. I am a QA-er if I haven't mentioned that already and some of the tests we run are pretty repetitive so sometimes, instead of just doing the work really slowly and manually like a caveman who just got his first Dell Laptop, I sit down and blunder my way through figuring out how to build automated testing structures and frameworks. Automating my tasks helps me cut down the time I spend on mind numbing tasks to a mere FRACTION (think 3/16ths, or like 2/33rds) of the time.

It's kind of funny though, this is not really what freelancers should be doing. If a freelancer is working per hour (like I do) shouldn't they spend every minute they can taking their time on things? Right? To milk all the money they can out of their clients?

Nah I hate that s#!+. I honestly hate doing repetitive work if I know there's an easier way to do more of it, faster and cheaper. However, the cost of implementing automation is usually very high. Often when I decide to write a script to automate something, I could have been done with the task I needed to do in only part of the time it took me to write the script. And another often, sometimes I completely fail at getting the script to work, or work in a helpful way.

Yesterday I wasn't writing scripts to automate things though, but actually using one of the scripts I wrote for some work which got me thinking that not enough people look at programming as a means of assistance in their workflow. I see people building "apps" and "single-page apps" and "web apps" ( into the "app" hole we go ) but never like "hey look at this great thing I made that cuts my time spent on this work by 4/57ths" ( in writing this I realize that some of the knowledge that you'd have to give out to share this would be proprietary to that person's client or company ).

The script I use isn't a full blown program, it's actually super poorly laid out and spits error print outs constantly but it does the job. There's no button I press or anything, I just import the script into a juptyer notebook and keep most of my notes there. What day I used it, comment out when I've already used it with a specifc account, so on and so forth.

THEN ( you forgot didn't you? I was recounting yesterday's coding activities ), that's when I dove into Dataquest with the numpys and what not. This is kind of what I learned on ...

DAY 14

In [8]:
# if I wanted to get the sum of every list INSIDE the bigger list, this is how I would do it in normal Python

my_numbers = [
    [6,5],
    [1,3],
    [5,6],
    [1,4],
    [3,7],
    [5,8],
    [3,5],
    [8,4]
]

sums = [] # makes a list to add things to.

for row in my_numbers:
    row_sum = row[0] + row[1] # here's where the adding happens and it's initialized to a variable..
    sums.append(row_sum) # that's then added to the list we created before.
    
sums # then we call it to show it off
Out[8]:
[11, 4, 11, 5, 10, 13, 8, 12]

seems pretty simple right? throw a for loop in there, easy peezy, get the job done. Here's how one would do it with numpy

In [9]:
my_numbers = [
    [6,5],
    [1,3],
    [5,6],
    [1,4],
    [3,7],
    [5,8],
    [3,5],
    [8,4]
]


my_numbers = numpy.array(my_numbers) # here we just turn the my_numbers list into a numpy array, numpy's very
# own data structure

column1 = my_numbers[:,0] # then we brilliant make our numbers into columns (which is what they are)
column2 = my_numbers[:,1] # be careful, you cannot use this kind of syntax on normal python lists, only numpy arrays

############################## the list selection syntax above is what I'm referring to from below #####################

sums = column1 + column2 # then we add those two columns to each other

sums # then we call it.
Out[9]:
array([11,  4, 11,  5, 10, 13,  8, 12])

I can even do it with less lines of code (something all python programmers are obsessed with)

In [10]:
my_numbers = [[6,5],[1,3],[5,6],[1,4],[3,7],[5,8],[3,5],[8,4]]

sums = numpy.array(my_numbers)[:,0] + numpy.array(my_numbers)[:,1] # everything from up there but squeezed into one line

sums
Out[10]:
array([11,  4, 11,  5, 10, 13,  8, 12])

BOOM

crazy right? Maybe none of that makes sense to you and you're just here for the great literature that my fingertips produce. Maybe you do program and you're all like "whoa dude how'd you do that without the for loop the second time?"

I'm so glad you asked.

APPARENTLY

numpy will initialize it's collection of numbers in a process called vectorization. How I think it works is that .....( I had to go review the lesson but I'm back now to explain it ) numpy can group data into blocks and run operations on that group, rather than just one item at a time which is what you're seeing with the normal python from above.

This is something I didn't know going into these lessons. I thought numpy was a advanced matrix and vector mathematics library for Python and that I would never use it for anything ever because I never do complex math on matrices or vectors but this sole feature alone is enough for me to try to always avoid using for loops if I can just use numpy. The syntax to select rows and columns in a numpy array is much more intuitive than it is for normal python list selection.

So that's really neat to learn.

That was all part of just a few tiny missions, I have barely made a dent in the material but I feel inspired just knowing this.

Alright. I think that's everything I wanted to bore you to tears with tonight.

Bye.