Python Day 20 – some numpy workarounds in practice

Just did more practice problems today.

I learned:

I figured out another way to get all the even values of an array! Instead of using the for-if function from yesterday, my friend gave me the hint that I could mask out the values with a boolean. So I put “mask = arrfloat%2==0” and “arrfloat[mask]” and it worked!! Very happy to have that figured out.

I also learned smaller formatting stuff like to use hstack you need to put np.hstack first.

A little frustration:

I’m still having to run all the code when I reopen Jupyter notebooks (so it defines my variables). There’s gotta be an easy workaround right? I realize while typing this that I haven’t even googled the problem hah. Give me one sec…

The overlords are telling me to press control + shift + alt + enter. It shall be done henceforth 🙂

I’m still confused on:

(this is from one of the practice problems)

Is there a way to get the average of a select few of the values in an array? Other than masking with a boolean? I tried np.mean(arr<50) which is giving me weird results between 0-1. I’m not completely sure what’s going on.

Alas, that shall be a problem for another day (likely tomorrow!). I shall get back to studying for my finance final.

Peace out, homies.

Keep it on the real.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: