Contents

Python NumPy For Your Grandma - 2.7 Challenge: High School Reunion

Intro To Challenges

In this video, we’re going to do the first of many challenges. I tried to make these challenges align with what we’ve already learned, but in some cases the solution requires a new function or trick that we haven’t discussed. That’s on purpose because in the real world the problems you come across aren’t limited to things you’ve already seen, so part of being a good data scientist is having the ability to search for a solution online, and to read and interpret documentation. So I’m going to encourage you to do all those things in your attempt to solve these problems.

Setup

With your high school reunion fast approaching, you decide to get in shape and lose some weight. You record your weight every day for five weeks starting on a Monday. Given these daily weights, build an array with your average weight per weekend.

So, here’s the setup code. It just produces an array with 35 values, where this first value represents your first recorded weight, 185 lbs, and that’s on a Monday.

import numpy as np

dailywts = 185 - np.arange(5*7)/5
print(dailywts)
## [185.  184.8 184.6 184.4 184.2 184.  183.8 183.6 183.4 183.2 183.  182.8
##  182.6 182.4 182.2 182.  181.8 181.6 181.4 181.2 181.  180.8 180.6 180.4
##  180.2 180.  179.8 179.6 179.4 179.2 179.  178.8 178.6 178.4 178.2]

Your goal is to build a 5-element array where each value gives your average weight on the corresponding weekend.

Solution

(dailywts[5::7] + dailywts[6::7])/2
## array([183.9, 182.5, 181.1, 179.7, 178.3])

Course Curriculum

  1. Introduction
    1.1 Introduction
  2. Basic Array Stuff
    2.1 NumPy Array Motivation
    2.2 NumPy Array Basics
    2.3 Creating NumPy Arrays
    2.4 Indexing 1-D Arrays
    2.5 Indexing Multidimensional Arrays
    2.6 Basic Math On Arrays
    2.7 Challenge: High School Reunion
    2.8 Challenge: Gold Miner
    2.9 Challenge: Chic-fil-A
  3. Intermediate Array Stuff
    3.1 Broadcasting
    3.2 newaxis
    3.3 reshape()
    3.4 Boolean Indexing
    3.5 nan
    3.6 infinity
    3.7 random
    3.8 Challenge: Love Distance
    3.9 Challenge: Professor Prick
    3.10 Challenge: Psycho Parent
  4. Common Operations
    4.1 where()
    4.2 Math Functions
    4.3 all() and any()
    4.4 concatenate()
    4.5 Stacking
    4.6 Sorting
    4.7 unique()
    4.8 Challenge: Movie Ratings
    4.9 Challenge: Big Fish
    4.10 Challenge: Taco Truck
  5. Advanced Array Stuff
    5.1 Advanced Array Indexing
    5.2 View vs Copy
    5.3 Challenge: Population Verification
    5.4 Challenge: Prime Locations
    5.5 Challenge: The Game of Doors
    5.6 Challenge: Peanut Butter
  6. Final Boss
    6.1 as_strided()
    6.2 einsum()
    6.3 Challenge: One-Hot-Encoding
    6.4 Challenge: Cumulative Rainfall
    6.5 Challenge: Table Tennis
    6.6 Challenge: Where’s Waldo
    6.7 Challenge: Outer Product

Additional Content

  1. Python Pandas For Your Grandpa
  2. Neural Networks For Your Dog
  3. Introduction To Google Colab