In [20]:
import numpy as np

In [21]:
a = np.array([[1,2,3],[4,5,6],[7,8,9]]) # making array

In [22]:
a  # displaying array

Out[22]:
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
In [23]:
a[a[:,1] > 2, 1] = 99 # boolean mapping

In [24]:
a # redisplay with new shit

Out[24]:
array([[ 1,  2,  3],
[ 4, 99,  6],
[ 7, 99,  9]])
In [17]:
b = np.arange(9).reshape(3,3) # making

In [18]:
b # before

Out[18]:
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
In [28]:
b[b[1,:] > 1, 1] = 47 # waves magic wand

In [29]:
b # after

Out[29]:
array([[ 0, 47,  2],
[ 3, 47,  5],
[ 6, 47,  8]])
In [31]:
c = np.arange(0,27,3).reshape(3,3) # make

In [32]:
c # just an oridinary simple array

Out[32]:
array([[ 0,  3,  6],
[ 9, 12, 15],
[18, 21, 24]])
In [34]:
c[c[2,:] % 6 == 0, 2] = 111 # abra cadabra

In [35]:
c # wallah

Out[35]:
array([[  0,   3, 111],
[  9,  12,  15],
[ 18,  21, 111]])
In [55]:
d = np.arange(0,115,13).reshape(3,3) # making

In [56]:
d # before

Out[56]:
array([[  0,  13,  26],
[ 39,  52,  65],
[ 78,  91, 104]])
In [59]:
d[d[:,1] == 52, 1] = 0.0 # some magic

In [75]:
d[d[:,1] == 52, 2] = 0 # more magic
d # after lots of magic

Out[75]:
array([[  0,  13,  26],
[ 39,   0,  65],
[ 78,  91, 104]])
In [66]:
e = np.arange(0,9,1).reshape(3,3) # making one more just for kicks

In [67]:
e # I want to see if I can make all the numbers around the center one(4) zeros

Out[67]:
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
In [68]:
e[e[:,:] != 4] = 0 # everything not equal to four, change to zero please.


In [76]:
e # call me the "magic man"

# actually please don't. that's a terrible nickname

Out[76]:
array([[0, 0, 0],
[0, 4, 0],
[0, 0, 0]])

array[array[row_for_comparison, column_for_comparison] == value_for_comparison, column_for_assignment] = new_value

^ I refer to this below ^

In [78]:
!date

Fri Sep  6 01:40:10 CDT 2019


Hello there stalker and welcome to

# DAY 8¶

Were you afraid for a second that this one was just going to be code? I wouldn't do that to you. Let me start with a riddle

True or False: a boolean index is a list of all the scariest versions of Lil Wayne's favorite drink.

Actually now that I think about it, that makes a lot of sense.

In programming, a boolean is a kind of data type. Also it's the last name of some guy who did something important at some time or another.

The data type is True or False. Watch.

In [74]:
bool_data_crap = True
other_bool_data_crap = False
"don't trip or you'll fall and get a ",type(bool_data_crap),type(other_bool_data_crap)

Out[74]:
("don't trip or you'll fall and get a ", bool, bool)

Bool is boolean for short. Python hates spelling things out not unlike me.

Up top is the basics in numpy (professionals pronounce it "Num-Pie", but I'm trying to push for "numpeee", it sounds way funnier to say outloud) to make a what is called a boolean index.

I tried to explain this concept a few days ago but I'll try again (more for me, less for you), it's using a condition to map True and False against values in an array and then using that map/index to augment/alter one of those values.

Well it was kind of tough. That jumble of code-looking words just above where I point out that I'm going to refer to it (find it? it's up there ^) was the key to understanding how boolean indexing works and it was provided by DQ as well. I had to change it a little bit but it was the format I tried to follow in all my practice above that.

If you ask me that's confusing as all hell but I'm sure my commenting helps right?

## RIGHT??¶

This is what that's all about: I've been working on the same "mission" on Dataquest for a few days now. This boolean indexing hurts my gourd. What's worse is that I do it correctly every time and I don't incur any errors.

How is that worse? Isn't not getting errors a good thing when you're programming?

Errors are my life blood. If code spits up an output, I understand it less than I do if I have an error. At least I know that I did something wrong and what I did wrong (if it's a well written error, remember, people write the errors too). I didn't understand what I was doing until array labeled as e up there. Seriously.

Also sometimes the Dataquest mission builders write sentences to make me think more coding is involved then necessary.

I'm going to bed now but I want to leave you with an important message.

Don't drink lean. It's bad for you.