├── .gitignore ├── README.md ├── matplotlib ├── beginner │ ├── dates-vs-derivatives.ipynb │ ├── drive-thru-daiquiris.ipynb │ ├── jerky-for-dogs.ipynb │ ├── koala-speeds.ipynb │ ├── seven.ipynb │ └── youre-a-legend.ipynb └── intermediate │ └── iris.ipynb ├── python-numpy ├── advanced │ ├── freckle.ipynb │ ├── get-rich-bot.ipynb │ ├── peanut-butter.ipynb │ ├── population-verification.ipynb │ ├── prime-locations.ipynb │ └── the-game-of-doors.ipynb ├── beginner │ ├── chic-fil-a.ipynb │ ├── gold-miner.ipynb │ ├── high-school-reunion.ipynb │ ├── nola.ipynb │ └── roux.ipynb ├── expert │ ├── cumulative-rainfall.ipynb │ ├── neural-network-convolution.ipynb │ ├── one-hot-encoding.ipynb │ ├── outer-product.ipynb │ ├── table-tennis.ipynb │ └── wheres-waldo.ipynb ├── intermediate │ ├── love-distance.ipynb │ ├── professor-prick.ipynb │ └── psycho-parent.ipynb └── proficient │ ├── big-fish.ipynb │ ├── defraud-the-investors.ipynb │ ├── movie-ratings.ipynb │ ├── pixel-artist.ipynb │ └── taco-truck.ipynb ├── python-pandas ├── advanced │ ├── class-transitions.ipynb │ ├── ob-gym.ipynb │ ├── product-volumes.ipynb │ ├── rose-thorn.ipynb │ └── session-groups.ipynb ├── dataframe │ ├── afols.ipynb │ ├── cradle-robbers.ipynb │ ├── hobbies.ipynb │ ├── humans.ipynb │ ├── party-time.ipynb │ ├── potholes.ipynb │ └── vending-machines.ipynb ├── final-boss │ ├── concerts.ipynb │ ├── covid-tracing.ipynb │ ├── family-iq.ipynb │ ├── pickle.ipynb │ └── tv-commercials.ipynb └── series │ ├── baby-names.ipynb │ ├── bees-knees.ipynb │ ├── car-shopping.ipynb │ ├── fair-teams.ipynb │ └── price-gouging.ipynb ├── python-sparse-matrices ├── dog-shelter.ipynb ├── mine-field.ipynb ├── movie-distance.ipynb ├── puny-computer.ipynb └── tinder-coach.ipynb ├── pytorch ├── basic-models │ └── pass-or-fail.ipynb └── tensors │ ├── fliptate.ipynb │ ├── random-block.ipynb │ ├── screen-time.ipynb │ └── vanilla-neural-network.ipynb └── regular-expressions-in-python ├── advanced ├── et.ipynb ├── groundhog-day.ipynb ├── iron-man.ipynb ├── lord-of-the-rings.ipynb ├── mean-girls.ipynb └── the-dark-knight.ipynb ├── beginner ├── gone-with-the-wind.ipynb ├── harry-potter.ipynb ├── spongebob-squarepants.ipynb ├── star-wars.ipynb └── the-simpsons.ipynb └── intermediate ├── its-always-sunny.ipynb ├── legally-blonde.ipynb └── napoleon-dynamite.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 105 | __pypackages__/ 106 | 107 | # Celery stuff 108 | celerybeat-schedule 109 | celerybeat.pid 110 | 111 | # SageMath parsed files 112 | *.sage.py 113 | 114 | # Environments 115 | .env 116 | .venv 117 | env/ 118 | venv/ 119 | ENV/ 120 | env.bak/ 121 | venv.bak/ 122 | 123 | # Spyder project settings 124 | .spyderproject 125 | .spyproject 126 | 127 | # Rope project settings 128 | .ropeproject 129 | 130 | # mkdocs documentation 131 | /site 132 | 133 | # mypy 134 | .mypy_cache/ 135 | .dmypy.json 136 | dmypy.json 137 | 138 | # Pyre type checker 139 | .pyre/ 140 | 141 | # pytype static type analyzer 142 | .pytype/ 143 | 144 | # Cython debug symbols 145 | cython_debug/ 146 | 147 | # PyCharm 148 | # JetBrains specific template is maintainted in a separate JetBrains.gitignore that can 149 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 150 | # and can be added to the global gitignore or merged into this file. For a more nuclear 151 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 152 | .idea/ 153 | 154 | # Mac OS 155 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/) 2 | 3 | Fun programming practice problems to help you learn 🚀 4 | 5 | # Problem Sets 6 | Most problems from [practiceprobs.com](https://www.practiceprobs.com/) are included here, but some problems only exist on the site. 7 | 8 | ## Notes 9 | - Not every problem on [practiceprobs.com](https://www.practiceprobs.com/) exists here. 10 | - Some problems here have a bit more explainer content on [practiceprobs.com](https://www.practiceprobs.com/). 11 | - Solutions are hosted on [practiceprobs.com](https://www.practiceprobs.com/). -------------------------------------------------------------------------------- /matplotlib/beginner/dates-vs-derivatives.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"dates-vs-derivatives.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Dates vs Derivatives](https://www.practiceprobs.com/problemsets/matplotlib/beginner/dates-vs-derivatives/)\n","\n","Thirty college students were surveyed on\n","\n","1. the number of derivatives they've calculated in the past year and\n","2. the number of dates they've been on in the past year"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import random\n","\n","random.seed(1)\n","derivatives = [random.randrange(0, 250) for i in range(30)]\n","dates = [random.randrange(0, max(50 - d, 3)) for d in derivatives]\n","\n","print(derivatives)\n","# [34, 145, 216, ..., 178, 114, 68]\n","\n","print(dates)\n","# [7, 2, 0, ..., 0, 1, 2]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a scatter plot of this data with\n","\n","- *derivatives* on the x axis and dates on y axis (with labeled axes)\n","- points using the color 'tab:red'\n","- the title:\n","\n"," *Dates vs Derivatives* \n"," *(for 30 college students surveyed about their recent year)*"],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/dates-vs-derivatives/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/beginner/drive-thru-daiquiris.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"drive-thru-daiquiris.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Drive Thru Daiquiris](https://www.practiceprobs.com/problemsets/matplotlib/beginner/drive-thru-daiquiris/)\n","\n","You own a chain of drive-thru daiquiris 🥤. (Yes, they exist.) Build a plot like the one below showing the distribution of sales per store, per hour."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(1234)\n","\n","p1 = [0.05, 0.03, 0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04,\n"," 0.07, 0.07, 0.08, 0.08, 0.08, 0.12, 0.15, 0.18, 0.15, 0.12, 0.08, 0.06]\n","p2 = np.concatenate((p1[-5:], p1[:-5]))\n","p3 = np.concatenate((p1[5:], p1[:5]))\n","\n","# sales per store\n","s1 = rng.choice(24, size=1000, replace=True, p=p1/np.sum(p1))\n","s2 = rng.choice(24, size=2000, replace=True, p=p2/np.sum(p2))\n","s3 = rng.choice(24, size=1750, replace=True, p=p3/np.sum(p3))\n","\n","print(s1[:5]) # [23 16 22 13 14] \n","print(s2[:5]) # [22 17 11 22 0]\n","print(s3[:5]) # [16 7 12 15 17]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/drive-thru-daiquiris/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/beginner/jerky-for-dogs.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"jerky-for-dogs.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Jerky For Dogs](https://www.practiceprobs.com/problemsets/matplotlib/beginner/jerky-for-dogs/)\n","\n","You sell homemade beef jerky for dogs at your local farmers market 🐶. After a few weeks of selling, you decide to analyze your *sales by date per flavor*."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","# Create a random number generator\n","rng = np.random.default_rng(1234) \n","\n","# Make data\n","dates = ['2022-01-01', '2022-01-08', '2022-01-15', '2022-01-22', '2022-01-29']\n","dates = np.repeat(np.array(dates, dtype='datetime64[D]'), repeats=4)\n","flavors = np.tile(['traditional', 'salsa', 'sweet orange', 'smokey'], reps=5)\n","sales = np.round(rng.lognormal(mean=3, sigma=2.5, size=len(dates)), 2)\n","dates, flavors, sales = dates[:-1], flavors[:-1], sales[:-1]\n","\n","print(dates) # ['2022-01-01' '2022-01-01' ... '2022-01-29' '2022-01-29']\n","print(flavors) # [ 'salsa' 'sweet orange' ... 'salsa' 'sweet orange']\n","print(sales) # [ 82.02 11.43 ... 1358.36 0.09]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a plot like the one below showcasing `sales` vs `date`, with a separate Axes for each `flavor`. Note that each Axes has the same x and y scale!"],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/jerky-for-dogs/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/beginner/koala-speeds.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"koala-speeds.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Koala Speeds](https://www.practiceprobs.com/problemsets/matplotlib/beginner/koala-speeds/)\n","\n","You believe there's a linear relationship between the weight of an adult koala 🐨 and how fast it runs. You gather some data."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","# Create a random number generator\n","rng = np.random.default_rng(4321) \n","\n","# Make data\n","weights = rng.uniform(low=10, high=20, size=35)\n","speeds = -0.08* weights + 7.2 + rng.normal(loc=0, scale=0.5, size=len(weights))\n","ages = rng.uniform(low=3, high=18, size=len(weights))\n","\n","print(weights) # [10.03 18.08 15.33 ... 17.07 13.32 10.08]\n","print(speeds) # [6.33 5.55 6.33 ... 5.48 6.41 6.55]\n","print(ages) # [12.51 11.16 10.36 ... 17.24 16.06 7.89]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["You fit a linear regression model to this data, `y = mx + b`, with slope `m = -0.15` and offset `b = 8.2`.\n","\n","- Make a scatter plot of *speed (y) vs weight (x)*, varying the size of each point by the koala's `age`.\n","- Overlay the linear regression line defined by `m` and `b`.\n","- Include the linear regression equation inside the Axes, near the top right. (**Make the position of the equation independent of the data!**)"],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/koala-speeds/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/beginner/seven.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"seven.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Seven](https://www.practiceprobs.com/problemsets/matplotlib/beginner/seven/)\n","\n","Here's a 2-D NumPy array representing the number seven."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","seven = np.array(\n"," [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 84,185,159,151, 60, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0,222,254,254,254,254,241,198,198,198,198,198,198,198,198,170, 52, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 67,114, 72,114,163,227,254,225,254,254,254,250,229,254,254,140, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 66, 14, 67, 67, 67, 59, 21,236,254,106, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83,253,209, 18, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22,233,254, 83, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,129,254,238, 44, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59,249,254, 62, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,133,254,187, 5, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,205,248, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,126,254,182, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75,251,240, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19,221,254,166, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,203,254,219, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38,254,254, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31,224,254,115, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,133,254,254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61,242,254,254, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,121,254,254,219, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,121,254,207, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n"," [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]\n",")"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["- The array represents a 28x28 grid of pixels\n","- Element (i,j) gives the luminosity of the ij pixel, on a scale from 0 to 255. (0 = black, 255 = white)\n","\n","Plot the image as shown below."],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/seven/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/beginner/youre-a-legend.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"youre-a-legend.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [You're a Legend!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/youre-a-legend/)\n","\n","Given this data,"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(1234)\n","x = np.linspace(start=0, stop=4*np.pi, num=100)\n","y_A = np.sin(x + 0.0 * np.pi) + rng.normal(scale=0.1, size=len(x))\n","y_B = np.sin(x + 0.5 * np.pi) + rng.normal(scale=0.1, size=len(x))\n","y_C = np.sin(x + 1.0 * np.pi) + rng.normal(scale=0.1, size=len(x))\n","y_D = np.sin(x + 1.5 * np.pi) + rng.normal(scale=0.1, size=len(x))\n","\n","colors = {'A': '#9D44B5', 'B': '#B5446E', 'C': '#525252', 'D': '#BADEFC'}"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["make this scatter plot."],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["**Notice the legend in the top right!** Do this, and you're a legend, mate! 🙌"],"metadata":{"id":"isV8MZMzKR26"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/beginner/youre-a-legend/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /matplotlib/intermediate/iris.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"iris.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Iris](https://www.practiceprobs.com/problemsets/matplotlib/intermediate/iris/)\n","\n","The [Iris Flower Dataset](https://en.wikipedia.org/wiki/Iris_flower_data_set) contains measurements on three species of iris flowers."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import pandas as pd\n","\n","# Fetch the data \n","iris = pd.read_csv(\"https://raw.githubusercontent.com/practiceprobs/datasets/main/iris/iris.csv\")\n","\n","# Inspect the first 5 rows\n","iris.head()\n","# sepal_length sepal_width petal_length petal_width species\n","# 0 5.1 3.5 1.4 0.2 Iris-setosa\n","# 1 4.9 3.0 1.4 0.2 Iris-setosa\n","# 2 4.7 3.2 1.3 0.2 Iris-setosa\n","# 3 4.6 3.1 1.5 0.2 Iris-setosa\n","# 4 5.0 3.6 1.4 0.2 Iris-setosa\n","\n","# Inspect the last 5 rows\n","iris.tail()\n","# sepal_length sepal_width petal_length petal_width species\n","# 145 6.7 3.0 5.2 2.3 Iris-virginica\n","# 146 6.3 2.5 5.0 1.9 Iris-virginica\n","# 147 6.5 3.0 5.2 2.0 Iris-virginica\n","# 148 6.2 3.4 5.4 2.3 Iris-virginica\n","# 149 5.9 3.0 5.1 1.8 Iris-virginica\n","\n","# Inspect the species values\n","iris.species.value_counts()\n","# Iris-setosa 50\n","# Iris-versicolor 50\n","# Iris-virginica 50\n","# Name: species, dtype: int64"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Suppose we want to build a model to predict *petal_length*. It'd be useful to visualize *petal_length* versus the other three continuous variables: *sepal_length*, *sepal_width*, and *petal_width*, each colored by *species*. Do that, mimicking the plot below.\n","\n","**Notes**\n","\n","- the plot style used in this example is [ggplot](https://matplotlib.org/3.5.1/gallery/style_sheets/ggplot.html).\n","- the Colormap used in this example is [brg](https://matplotlib.org/3.5.1/tutorials/colors/colormaps.html#miscellaneous)."],"metadata":{"id":"PQhSBjgDHtcM"}},{"cell_type":"markdown","source":["## Expected Plot\n","\n",""],"metadata":{"id":"42ONCyRPH8X5"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/matplotlib/intermediate/iris/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/freckle.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"freckle.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Freckle](https://www.practiceprobs.com/problemsets/python-numpy/advanced/freckle/)\n","\n","Given a 1-D array called `freckle`,"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","freckle = np.array([2,7,3,1,0,5])"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["perform the following sequence of operations:\n","\n","1. Sort the elements in descending order:\t\n"," `7, 5, 3, 2, 1, 0`\n"," \n","2. Take their cumulative sum:\t\n"," `7, 12, 15, 17, 18, 18`\n"," \n","3. Undo the sort from step 1:\t\n"," `17, 7, 15, 18, 18, 12`"],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/freckle/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/get-rich-bot.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"get-rich-bot.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Get Rich Bot](https://www.practiceprobs.com/problemsets/python-numpy/advanced/get-rich-bot/)\n","\n","You've developed an algorithmic stock trading bot to strike it rich 🤑, but you want to backtest it before putting it into production. You have price data on 10 stocks, each tracked at 8 regular time intervals."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(1234)\n","prices = [rng.normal(rng.lognormal(3, 1), size=8).round(2) for i in range(10)]\n","prices = np.vstack(prices)\n","\n","print(prices) \n","# [[ 4.1 4.78 4.19 4.9 6.95 2.56 4.99 2.37]\n","# [ 27.81 29.65 27.46 28.84 27.06 26.17 28.76 30.06]\n","# [ 32.79 34.06 34.56 34.98 32.63 34.49 34.14 33.76]\n","# [ 19.67 19.73 21.68 20.61 19.87 17.86 19.48 19.85]\n","# [ 4.24 6.39 5.32 3.87 4.23 5.27 6.68 4.06]\n","# [ 98.02 96.79 99.02 99.94 98.28 99.15 98.19 98.49]\n","# [107.11 105.01 109.01 105.19 107.06 106.71 106.13 106.41]\n","# [ 17.89 16.34 15.88 17.53 18.79 16.91 18.75 16.96]\n","# [ 96.28 95.84 96.26 94.48 95.42 93.75 93.54 96.24]\n","# [ 18.31 17.43 16.53 20.2 18.68 17.48 17.33 18.96]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["For each stock, your algorithm suggests the best time to buy the stock and the best time to sell the stock."],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"code","source":["trade_idxs = [np.sort(rng.choice(8, size=2, replace=False)) for i in range(10)]\n","trade_idxs = np.vstack(trade_idxs)\n","\n","print(trade_idxs) \n","# [[0 1]\n","# [3 6]\n","# [2 4]\n","# [1 5]\n","# [0 3]\n","# [2 7]\n","# [2 3]\n","# [1 3]\n","# [3 6]\n","# [1 4]]"],"metadata":{"id":"zuGoMwcBo5qG"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["trade_idxs identifies the index of the buy price and sell price for each stock. So, the holding periods look like this.\n","\n","```\n","| trade_idxs | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n","|:-----------|------:|------:|------:|-------:|------:|------:|------:|------:|\n","| [0 1] | 4.1 | 4.78 | ----- | ----- | ----- | ----- | ----- | ----- |\n","| [3 6] | ----- | ----- | ----- | 28.84 | 27.06 | 26.17 | 28.76 | ----- |\n","| [2 4] | ----- | ----- | 34.56 | 34.98 | 32.63 | ----- | ----- | ----- |\n","| [1 5] | ----- | 19.73 | 21.68 | 20.61 | 19.87 | 17.86 | ----- | ----- |\n","| [0 3] | 4.24 | 6.39 | 5.32 | 3.87 | ----- | ----- | ----- | ----- |\n","| [2 7] | ----- | ----- | 99.02 | 99.94 | 98.28 | 99.15 | 98.19 | 98.49 |\n","| [2 3] | ----- | ----- | 09.01 | 105.19 | ----- | ----- | ----- | ----- |\n","| [1 3] | ----- | 16.34 | 15.88 | 17.53 | ----- | ----- | ----- | ----- |\n","| [3 6] | ----- | ----- | ----- | 94.48 | 95.42 | 93.75 | 93.54 | ----- |\n","| [1 4] | ----- | 17.43 | 16.53 | 20.2 | 18.68 | ----- | ----- | ----- |\n","```\n","\n","Given `prices` and `trade_idxs`, calculate the average price of each *holding period*."],"metadata":{"id":"5kzxScexo7jL"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/get-rich-bot/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/peanut-butter.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"peanut-butter.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Peanut Butter](https://www.practiceprobs.com/problemsets/python-numpy/advanced/peanut-butter/)\n","\n","Given `peanut`, a 4x5 array of 0s, and `butter`, a 5-element 1-d array of indices, fill the rows of `peanut` with 1s starting from the column indices given by `butter`."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","peanut = np.zeros(shape = (4, 5))\n","butter = np.array([3, 0, 4, 1])\n","\n","print(peanut)\n","# [[0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0.]]\n","\n","print(butter)\n","# [3 0 4 1]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/peanut-butter/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/population-verification.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"population-verification.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Population Verification](https://www.practiceprobs.com/problemsets/python-numpy/advanced/population-verification/)\n","\n","You manage a local department for the Census responsible for measuring the population of each block in your city . Even though you could do it yourself, for each of the last five years, you’ve tasked this job to your subordinate, Jim.\n","\n","Each year, Jim gives you a 2x4 array of his population estimates where each element of the array represents a city block. After five years, you have a 5x2x4 array of population estimates called `jim` where (i,j,k) represents Jim’s population estimate for block (j,k) of year i."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(2357)\n","jim = np.round(generator.normal(loc=100, scale=5, size=(5,2,4)))\n","\n","print(jim)\n","# [[[106. 103. 92. 100.]\n","# [ 94. 102. 94. 100.]]\n","# \n","# [[104. 96. 109. 96.]\n","# [101. 104. 102. 92.]]\n","# \n","# [[102. 102. 108. 101.]\n","# [ 91. 101. 106. 99.]]\n","# \n","# [[101. 98. 95. 102.]\n","# [100. 101. 99. 93.]]\n","# \n","# [[107. 101. 104. 105.]\n","# [102. 97. 101. 102.]]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["**You don’t fully trust Jim’s estimates** because you see him spending an ungodly amount of time on Facebook. So, each year, you go behind his back and measure the population of two city blocks. After five years, you have the following data:\n","\n","- `blocks`, a 5x2x2 array indicating which blocks you measured each year where (i,j) gives the coordinates for the jth block you measured in year i\n","- `pops`, a corresponding 5x2 array where (i,j) gives the population you measured for the jth block in year i"],"metadata":{"id":"w9EsBXWUhpCa"}},{"cell_type":"code","source":["blocks = np.array([\n"," [[0,2],[1,3]],\n"," [[1,2],[0,0]],\n"," [[0,0],[1,2]],\n"," [[1,1],[0,3]],\n"," [[0,1],[1,0]]\n","])\n","\n","pops = np.array([\n"," [100, 105],\n"," [110, 92],\n"," [95, 99],\n"," [89, 107],\n"," [101, 98]\n","])"],"metadata":{"id":"7FPkR3y3lorO"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["How many times was Jim’s estimate at least 10% higher or lower than your estimate?"],"metadata":{"id":"XnPQZu9ols-v"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/population-verification/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/prime-locations.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"prime-locations.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Prime Locations](https://www.practiceprobs.com/problemsets/python-numpy/advanced/prime-locations/)\n","\n","Given a 10x10x10 array of zeros, set (i,j,k) = 1 if i is odd, j is even, and k is prime.\n","\n","In other words, set these elements to 1: (1,0,2), (1,0,3), (1,0,5), (1,0,7), (1,2,2), ..."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","chewy = np.zeros((10,10,10))\n","\n","print(chewy)\n","# [[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0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\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/prime-locations/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/advanced/the-game-of-doors.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"the-game-of-doors.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [The Game Of Doors](https://www.practiceprobs.com/problemsets/python-numpy/advanced/the-game-of-doors/)\n","\n","You’re preparing for a game show where you play the following game.\n","\n","You’re faced with four doors \\[?\\] \\[?\\] \\[?\\] \\[?\\] \n","Behind one door is cash money 🤑 \n","Behind the other three doors is steaming pile of broccoli 🥦 \n","\n","If you pick the door with money, you get the option to play again at the risk of losing the money you’ve collected thus far. If you keep winning, you can play a maximum of three rounds before the game show host kicks you off his show.\n","\n","You have some strategy ideas you’d like to evaluate before you go on the show. You hire an unpaid intern to scour through historic recordings of the show and log data on where prizes were located and the value of each prize.\n","\n","Your intern gets back to you with the following matrices:\n","\n","- `prize_doors`: Here, element (i,j) identifies the door hiding the prize in the ith game of round j\n","- `prizes`: Here (i, j) gives the prize amount in the ith game of round j\n","\n"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","prize_doors = np.array([\n"," [1, 0, 2],\n"," [0, 0, 1],\n"," [3, 3, 1],\n"," [1, 2, 0],\n"," [2, 1, 1]\n","])\n","\n","prizes = np.array([\n"," [100, 150, 500],\n"," [200, 300, 250],\n"," [150, 100, 325],\n"," [425, 200, 100],\n"," [200, 250, 300]\n","])"],"metadata":{"id":"ZlHN2R3QaPX3","executionInfo":{"status":"ok","timestamp":1650234001096,"user_tz":300,"elapsed":3,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["Build a 5x3x4 matrix where (i,j,k) represents the prize behind door k of round j of game i."],"metadata":{"id":"5bT2iej9nJSG"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/advanced/the-game-of-doors/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/beginner/chic-fil-a.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"chic-fil-a.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Chic-fil-A](https://www.practiceprobs.com/problemsets/python-numpy/beginner/chic-fil-a/)\n","\n","You decide to invest in a series of billboards along interstate 10 to advertise your stylish new chicken restaurant, Chic-fil-A 🐔.\n","\n","1. You buy three billboards evenly spaced starting from mile marker 17 and ending on mile marker 28.\n","2. You buy another three billboards starting on mile marker 32 and ending on mile marker 36.\n","3. In order, from mile marker 17 to 36, your billboards display these ads: A, B, C, C, B, A.\n","\n","Determine how far each B ad is from your restaurant which is located at mile marker 30.\n","\n","```\n","# ads / restaurant*: A B C * C B A\n","# billboards: --|-----|-----|---|---|--|--|--\n","# mile markers: 17 28 30 32 36\n","```"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np"],"metadata":{"id":"ZlHN2R3QaPX3","executionInfo":{"status":"ok","timestamp":1650231173086,"user_tz":300,"elapsed":3,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/beginner/chic-fil-a/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/beginner/gold-miner.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"gold-miner.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Gold Miner](https://www.practiceprobs.com/problemsets/python-numpy/beginner/gold-miner/)\n","\n","After binge watching the Discovery channel, you ditch your job as a trial lawyer to become a gold miner. You decide to prospect five locations underneath a 7x7 grid of land. How much gold do you uncover at each location?"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","np.random.seed(5555)\n","gold = np.random.randint(low=0, high=10, size=(7,7))\n","\n","print(gold)\n","# [[2 3 0 5 2 0 3]\n","# [8 8 0 7 1 5 3]\n","# [0 1 6 2 1 4 5]\n","# [4 0 8 9 9 8 7]\n","# [4 2 7 0 7 2 1]\n","# [9 8 9 2 5 0 8]\n","# [1 9 8 2 6 4 3]]\n","\n","locs = np.array([\n"," [0,4],\n"," [2,2],\n"," [2,3],\n"," [5,1],\n"," [6,3]\n","])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ZlHN2R3QaPX3","executionInfo":{"status":"ok","timestamp":1650230550900,"user_tz":300,"elapsed":5,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}},"outputId":"0bec401d-37b3-4877-c270-d3a148bdea2e"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["[[2 3 0 5 2 0 3]\n"," [8 8 0 7 1 5 3]\n"," [0 1 6 2 1 4 5]\n"," [4 0 8 9 9 8 7]\n"," [4 2 7 0 7 2 1]\n"," [9 8 9 2 5 0 8]\n"," [1 9 8 2 6 4 3]]\n"]}]},{"cell_type":"markdown","source":["**Notes**\n","\n","- `gold` states how much gold is under each location in the 7x7 grid of land\n","- `locs` states the coordinates of the five locations where you dig\n"],"metadata":{"id":"xsPF49EvaBAM"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/beginner/gold-miner/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/beginner/high-school-reunion.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"high-school-reunion.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [High School Reunion](https://www.practiceprobs.com/problemsets/python-numpy/beginner/high-school-reunion/)\n","\n","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."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","dailywts = 185 - np.arange(5*7)/5\n","\n","print(dailywts)\n","# [185. 184.8 184.6 184.4 184.2 184. 183.8 183.6 183.4 183.2 183. 182.8\n","# 182.6 182.4 182.2 182. 181.8 181.6 181.4 181.2 181. 180.8 180.6 180.4\n","# 180.2 180. 179.8 179.6 179.4 179.2 179. 178.8 178.6 178.4 178.2]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/beginner/high-school-reunion/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/beginner/nola.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"nola.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Nola](https://www.practiceprobs.com/problemsets/python-numpy/beginner/nola/)\n","\n","Make the following 4x7 array called nola that starts with 1 and steps by 2. However, note that the first element in each row is always 4 more than the last element in the previous row.\n","\n","```\n","# nola\n","[[ 1 3 5 7 9 11 13]\n"," [17 19 21 23 25 27 29]\n"," [33 35 37 39 41 43 45]\n"," [49 51 53 55 57 59 61]]\n","```"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/beginner/nola/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/beginner/roux.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"roux.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Roux](https://www.practiceprobs.com/problemsets/python-numpy/beginner/roux/)\n","\n","Define a *roux* array as a 1-D array such that, when it's reversed, it represents the sequence of square numbers 1, 4, 9, 16, ... with 0s interwoven between them.\n","\n","**Examples** \n","\n","```\n","# roux array of length 5\n","[9 0 4 0 1]\n","```\n","\n","```\n","# roux array of length 8\n","[ 0 16 0 9 0 4 0 1]\n","```\n","\n","```\n","# roux array of length 12\n","[ 0 36 0 25 0 16 0 9 0 4 0 1]\n","```\n","\n","**Note**: odd-length arrays begin with a square number while even-length arrays begin with a zero.\n","\n","Implement a function called `make_roux(n)` that inputs `n`, the desired size of the array, and outputs the corresponding roux array. Then test it on the examples above."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["def make_roux(n):\n"," \"\"\"returns a roux array of length n\"\"\"\n","\n"," # your code here"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/beginner/roux/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/cumulative-rainfall.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"cumulative-rainfall.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Cumulative Rainfall](https://www.practiceprobs.com/problemsets/python-numpy/expert/cumulative-rainfall/)\n","\n","Your job is to monitor the rainfall 🌧 in a region that you’ve broken into a 3x4 grid. Every time a storm comes, if a cell in the grid gets rain, you record it. At the end of a month you have the following two arrays of data."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rain_locations = np.array([\n"," [2,3],\n"," [0,1],\n"," [2,2],\n"," [2,3],\n"," [1,1],\n"," [2,3],\n"," [1,1]\n","])\n","\n","rain_amounts = np.array([0.5,1.1,0.2,0.9,1.3,0.4,2.0])"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a 3x4 array representing the total accumulated rainfall in each cell of the grid."],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/cumulative-rainfall/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/neural-network-convolution.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"neural-network-convolution.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Neural Network Convolution](https://www.practiceprobs.com/problemsets/python-numpy/expert/neural-network-convolution/)\n","\n","Suppose you have a 2-D array, `arr`,"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","arr = np.array([\n"," [0.15, 0.71, 0.26, -0.11, -2.03],\n"," [0.13, 0.44, -0.11, -0.23, 0.19],\n"," [-1.44, 0.51, 0.42, 2.58, -0.88],\n"," [-1.18, 2.73, 2.35, 0.21, -0.29],\n"," [-1.64, -0.37, 0.27, 0.57, 1.82]\n","])"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["and another, smaller 2-D array, `filter`,"],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"code","source":["filter = np.array([\n"," [0.08, 0.27, -0.24],\n"," [-0.25, -0.11, -0.18],\n"," [0.44, 1.87, 1.18]\n","])"],"metadata":{"id":"aLWnJE9mESNR"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["In the context of neural networks, a convolution works by \"sliding\" `filter` over `arr` in row major order (left to right, top to bottom), taking the dot product between `filter` and the portion of `arr` it covers at each step.\n","\n","![](https://www.practiceprobs.com/problemsets/python-numpy/images/convolution.gif)\n","\n","The result of all these dot products is the following 3x3 array.\n","\n","```\n","[[ 0.9 4.15 4.47]\n"," [ 7.74 5.27 0.74]\n"," [-1.6 -0.43 3.72]]\n","```"],"metadata":{"id":"uv7XnieqEULz"}},{"cell_type":"markdown","source":["Now suppose `arr` is the following 33x33x3 array."],"metadata":{"id":"hRTmpIMgElLz"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(123)\n","arr = rng.normal(size=(33,33,3)).round(2)\n","\n","print(arr)\n","# [\n","# [[-0.99 -0.37 1.29]\n","# [ 0.19 0.92 0.58]\n","# [-0.64 0.54 -0.32]\n","# ...\n","# [ 1.23 0.15 0.48]\n","# [-0.15 1.32 -1.22]\n","# [-0.3 -1.17 0.83]]\n","# \n","# [[ 0.85 -0.52 1.66]\n","# [-0.3 -1.38 -0.28]\n","# [ 0.36 -0.23 2.27]\n","# ...\n","# [ 1.52 0.49 0.7 ]\n","# [ 0.85 -0.91 0.12]\n","# [ 0.15 -0.16 -1.09]]\n","# \n","# ...\n","# \n","# [[-0.38 -0.45 1. ]\n","# [-0.58 2.18 0.36]\n","# [-0.44 -2.77 0.82]\n","# ...\n","# [-1.58 -0.5 -0.52]\n","# [-0.86 -0.54 -0.26]\n","# [ 0.23 0.81 -0.4 ]]\n","# \n","# [[-1.98 -0.22 -0.79]\n","# [-0.01 -1.47 -0.83]\n","# [-0.87 0.3 -0.82]\n","# ...\n","# [ 1.42 0.7 -0.75]\n","# [-0.81 1.68 -0.82]\n","# [-0.93 0.28 -1.61]]\n","# ]"],"metadata":{"id":"ViwroV9pEn3b"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["And let `filter` be the following 5x5x3 array."],"metadata":{"id":"hbM0MEfxEqAq"}},{"cell_type":"code","source":["filter = rng.normal(size=(5,5,3)).round(2)\n","\n","print(filter)\n","# [\n","# [[-1.47 0.74 0.58]\n","# [ 0.46 2.37 0.79]\n","# [ 1.15 -1.11 -0.29]\n","# [-0.98 0.29 0.44]\n","# [-0.44 -0.03 0.69]]\n","# \n","# [[ 0.34 0.67 -0.11]\n","# [-0.71 -1. -0.88]\n","# [ 0.61 0.49 -0.27]\n","# [ 0.12 -1.56 0.11]\n","# [ 0.32 -0.98 0.46]]\n","# \n","# [[-1.03 0.58 0.08]\n","# [ 0.89 0.86 1.49]\n","# [-0.4 0.86 -0.29]\n","# [ 0.07 -0.09 -0.87]\n","# [ 0.2 1.22 -0.27]]\n","# \n","# [[ 1.1 -2.61 1.64]\n","# [-1.15 0.47 1.44]\n","# [-1.45 0.39 1.37]\n","# [ 0.13 -0.1 0.04]\n","# [ 0.27 0.57 0.57]]\n","# \n","# [[-0.61 -0.41 0.93]\n","# [ 1.47 -0.07 -0.29]\n","# [ 0.49 1.02 0.2 ]\n","# [ 0.16 0.95 0.52]\n","# [ 1.11 0.13 -0.17]]\n","# ]"],"metadata":{"id":"v6NW4AcMEtVb"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Using strides of length two, calculate the convolution between these arrays. (The result should have shape 15x15.)"],"metadata":{"id":"hrIJcbGzEvpl"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/neural-network-convolution/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/one-hot-encoding.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"one-hot-encoding.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [One-Hot-Encoding](https://www.practiceprobs.com/problemsets/python-numpy/expert/one-hot-encoding/)\n","\n","Given a 1-D array of integers, [one-hot-encode](https://en.wikipedia.org/wiki/One-hot#Machine_learning_and_statistics) it into a 2-D array. In other words, convert this 1-D array called `yoyoyo`,"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","yoyoyo = np.array([3, 1, 0, 1])"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["into a 2-D array like this.\n","\n","```\n","# [[0. 0. 0. 1.]\n","# [0. 1. 0. 0.]\n","# [1. 0. 0. 0.]\n","# [0. 1. 0. 0.]]\n","```"],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/one-hot-encoding/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/outer-product.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"outer-product.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Outer Product](https://www.practiceprobs.com/problemsets/python-numpy/expert/outer-product/)\n","\n","Calculate the element-wise [outer product](https://en.wikipedia.org/wiki/Outer_product) of two matrices, `A` & `B`."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","A = np.arange(10*3).reshape((10,3))\n","B = np.arange(10*5).reshape((10,5))\n","\n","print(A)\n","# [[ 0 1 2]\n","# [ 3 4 5]\n","# [ 6 7 8]\n","# [ 9 10 11]\n","# [12 13 14]\n","# [15 16 17]\n","# [18 19 20]\n","# [21 22 23]\n","# [24 25 26]\n","# [27 28 29]]\n","\n","print(B)\n","# [[ 0 1 2 3 4]\n","# [ 5 6 7 8 9]\n","# [10 11 12 13 14]\n","# [15 16 17 18 19]\n","# [20 21 22 23 24]\n","# [25 26 27 28 29]\n","# [30 31 32 33 34]\n","# [35 36 37 38 39]\n","# [40 41 42 43 44]\n","# [45 46 47 48 49]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["The result should be a 10x3x5 array where the ith 3x5 array is the outer product of Ai and Bi."],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/outer-product/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/table-tennis.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"table-tennis.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Table Tennis](https://www.practiceprobs.com/problemsets/python-numpy/expert/table-tennis/)\n","\n","You manage a recreational table tennis league. There are 10 participants, and in an effort to make the first round of matchups as exciting as possible, you develop a model that predicts the score difference for every possible pair of players. That is, you produce a 10x10 matrix where (i,j) represents your prediction for player i’s score minus player j’s score if they were to compete."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(0)\n","score_diffs = np.round(generator.uniform(low=-15, high=15, size=(10,10)), 2)\n","np.fill_diagonal(score_diffs, np.nan)\n","score_diffs[np.triu_indices(10, k=1)[::-1]] = -score_diffs[np.triu_indices(10, k=1)]\n","\n","print(score_diffs)\n","# [[ nan -6.91 -13.77 -14.5 9.4 12.38 3.2 6.88 1.31 13.05]\n","# [ 6.91 nan 10.72 -13.99 6.89 -9.73 10.9 1.24 -6.01 -2.32]\n","# [ 13.77 -10.72 nan 4.42 3.46 -3.49 14.92 14.43 5.57 4.51]\n","# [ 14.5 13.99 -4.42 nan 0.76 -5.69 -0.42 11.68 13.02 -4.27]\n","# [ -9.4 -6.89 -3.46 -0.76 nan 11.71 -8.19 3.7 -12.48 9.98]\n","# [-12.38 9.73 3.49 5.69 -11.71 nan -1.49 8.89 -8.08 -13.44]\n","# [ -3.2 -10.9 -14.92 0.42 8.19 1.49 nan 13.26 -4.05 -11.84]\n","# [ -6.88 -1.24 -14.43 -11.68 -3.7 -8.89 -13.26 nan 13.47 -1.2 ]\n","# [ -1.31 6.01 -5.57 -13.02 12.48 8.08 4.05 -13.47 nan 6.87]\n","# [-13.05 2.32 -4.51 4.27 -9.98 13.44 11.84 1.2 -6.87 nan]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Given this matrix, determine the “best” schedule for round one - the schedule whose matchups minimize the sum of squared point differentials."],"metadata":{"id":"vOLTbQVgoBdb"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/table-tennis/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/expert/wheres-waldo.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"wheres-waldo.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Where's Waldo](https://www.practiceprobs.com/problemsets/python-numpy/expert/wheres-waldo/)\n","\n","Given a 1-million element array where each element is a random character in a-z, identify the starting index of every sequence of characters that spells ‘waldo’. Include sequences where at least 4 of the 5 characters match (e.g. ‘waldo’, 'wafdo', and ‘xaldo’ but not ‘wadlo’)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import string\n","\n","generator = np.random.default_rng(123)\n","chars = generator.choice(list(string.ascii_lowercase), size=10**6, replace=True)\n","\n","print(chars[:10])\n","# ['a' 'r' 'p' 'b' 'x' 'f' 'g' 'e' 'i' 'e']"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/expert/wheres-waldo/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/intermediate/love-distance.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"love-distance.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Love Distance](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/love-distance/)\n","\n","You’re a relationship scientist, and you’ve developed a questionnaire that determines a person’s *love score* - a real-valued number between 0 and 100. Your theory is that two people with similar love scores should make a good match 👩‍❤️‍💋‍👨\n","\n","Given the love scores for 10 different people, create a 2-d array where (i,j) gives the absolute difference of the love scores for person i and person j."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(1010)\n","love_scores = np.round(generator.uniform(low=0, high=100, size=10), 2)\n","\n","print(love_scores)\n","# [ 9.5 53.58 91.77 98.15 84.88 74.61 40.94 56.49 8.39 64.69]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/love-distance/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/intermediate/professor-prick.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"professor-prick.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Professor Prick](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/professor-prick/)\n","\n","You’re a vindictive professor 👨‍🏫 and one of your pet peeves is when students rush through their exams. To teach them a lesson, you decide to give zeros to the first three students who score less than sixty, in the order they turned in their exams.\n","\n","Given a 1-d array of integers, identify the first three values less than sixty and replace them with zero."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(80085)\n","scores = np.round(generator.uniform(low=30, high=100, size=15))\n","\n","print(scores)\n","# [68. 36. 76. 57. 56. 54. 63. 64. 36. 88. 80. 82. 84. 76. 42.]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/professor-prick/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/intermediate/psycho-parent.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"psycho-parent.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Pyscho Parent](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/psycho-parent/)\n","\n","Eager to make your mark on the PTA, you decide the best way to hide eggs for the upcoming Easter egg hunt is to use NumPy . You represent the field as a 10x10 array of 0s."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","field = np.zeros(shape = (10, 10))\n","\n","print(field)\n","# [[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n","# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Insert 20 random normal values at random (non repeating) locations in the grid. Then you'll know how much candy to hide at each spot."],"metadata":{"id":"T-lElEsKg-51"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/intermediate/psycho-parent/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/proficient/big-fish.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"big-fish.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Big Fish](https://www.practiceprobs.com/problemsets/python-numpy/proficient/big-fish/)\n","\n","10 fish occupy a 5x5x5 grid of water 🐟. Each fish decides to move to a new (i,j,k) location given by the 2-d array below. If multiple fish end up occupying the same cell, the biggest fish eats the smaller fish. Determine which fish survive."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","locs = np.array([\n"," [0,0,0],\n"," [1,1,2],\n"," [0,0,0],\n"," [2,1,3],\n"," [5,5,4],\n"," [5,0,0],\n"," [5,0,0],\n"," [0,0,0],\n"," [2,1,3],\n"," [1,3,1]\n","])\n","\n","generator = np.random.default_rng(1010)\n","weights = generator.normal(size=10)\n","\n","print(weights)\n","# [-1.699 0.538 -0.226 -1.09 0.554 -1.501 0.445 1.345 -1.124 0.212]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/proficient/big-fish/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/proficient/defraud-the-investors.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"defraud-the-investors.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Defraud The Investors](https://www.practiceprobs.com/problemsets/python-numpy/proficient/defraud-the-investors/)\n","\n","You've developed a model that predicts the probability a 🏠 house for sale can be flipped for a profit 💸. **Your model isn't very good**, as indicated by its predictions on historic data."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(123)\n","targets = rng.uniform(low=0, high=1, size=20) >= 0.6\n","preds = np.round(rng.uniform(low=0, high=1, size=20), 2)\n","\n","print(targets)\n","print(preds)\n","# [ True False False ... False True False]\n","# [ 0.23 0.17 0.50 ... 0.87 0.30 0.53]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Your investors want to see these results, but you're afraid to share them. You devise the following algorithm to make your predictions look better without looking artificial.\n","\n","```\n","Step 1: \n"," Choose 5 random indexes (without replacement)\n","\n","Step 2: \n"," Perfectly reorder the prediction scores at these indexes \n"," to optimize the accuracy of these 5 predictions\n","```\n","\n","**For example** \n","\n","If you had these prediction scores and truths\n","\n","```\n","indexes: [ 0, 1, 2, 3, 4]\n","scores: [ 0.3, 0.8, 0.2, 0.6, 0.3]\n","truths: [True, False, True, False, True]\n","```\n","\n","and you randomly selected indexes 1, 2, and 4, you would reorder their scores like this.\n","\n","```\n","indexes: [ 0, 1, 2, 3, 4]\n","old_scores: [ 0.3, 0.8, 0.2, 0.6, 0.3]\n","new_scores: [ 0.3, 0.2, 0.3, 0.6, 0.8]\n","truths: [True, False, True, False, True]\n","```\n","\n","This boosts your accuracy rate from 0% to 20%."],"metadata":{"id":"w9EsBXWUhpCa"}},{"cell_type":"markdown","source":["Here's some code to help you evaluate the accuracy of your predictions before and after your changes."],"metadata":{"id":"o1sCpVdbkB0V"}},{"cell_type":"code","source":["def accuracy_rate(preds, targets):\n"," return np.mean((preds >= 0.5) == targets)"],"metadata":{"id":"MVSNTx6HkBJX"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Accuracy before finagling\n","accuracy_rate(preds, targets) # 0.3"],"metadata":{"id":"XOMy0yxekdhR"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/proficient/defraud-the-investors/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/proficient/movie-ratings.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"movie-ratings.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Movie Ratings](https://www.practiceprobs.com/problemsets/python-numpy/proficient/movie-ratings/)\n","\n","You’re given a 10x2 array of floats where each row represents a movie. The first column represents the movie’s rating and the second column represents the director’s rating."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(123)\n","ratings = np.round(generator.uniform(low=0.0, high=10.0, size=(10, 2)))\n","ratings[[1,2,7,9], [0,0,0,0]] = np.nan\n","\n","print(ratings)\n","# [[ 7. 1.]\n","# [nan 2.]\n","# [nan 8.]\n","# [ 9. 3.]\n","# [ 8. 9.]\n","# [ 5. 2.]\n","# [ 8. 2.]\n","# [nan 6.]\n","# [ 9. 2.]\n","# [nan 5.]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Create a third column that represents the overall rating. The overall rating is equal to the movie rating if it exists, otherwise the director’s rating."],"metadata":{"id":"w9EsBXWUhpCa"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/proficient/movie-ratings/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/proficient/pixel-artist.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"pixel-artist.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Pixel Artist](https://www.practiceprobs.com/problemsets/python-numpy/proficient/pixel-artist/)\n","\n","You're a pixel artist 👩‍🎨. You have a collection of five 10x10-pixel images stored in a 5x3x10x10 array."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","rng = np.random.default_rng(1234)\n","imgs = rng.uniform(low=0, high=1, size=(5,3,10,10))"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["The (i,j,k,l) element corresponds to the ith image, jth color channel (RGB), kth row of pixels, jth column of pixels.\n","\n","You want to plot these images, but your plotting software expects color channel to be the last dimension of the array. Rearrange your array accordingly."],"metadata":{"id":"w9EsBXWUhpCa"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/proficient/pixel-artist/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-numpy/proficient/taco-truck.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"taco-truck.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Taco Truck](https://www.practiceprobs.com/problemsets/python-numpy/proficient/taco-truck/)\n","\n","You own a taco truck that’s open 24/7 and manage five employees who run it. Employees work solo, eight-hour shifts. You decide the best way to set their schedule for the upcoming week is to create a bunch of random schedules and select one that looks best.\n","\n","You build a 1000x21 array of random employee ids where element (i,j) gives the employee id working shift j for schedule i."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","generator = np.random.default_rng(999)\n","schedules = generator.integers(low=0, high=5, size=(1000, 21))\n","\n","print(schedules)\n","# [[4 3 0 ... 2 0 0]\n","# [2 4 3 ... 3 3 2]\n","# [1 0 1 ... 1 2 1]\n","# ...\n","# [2 2 1 ... 3 1 4]\n","# [1 0 3 ... 2 3 2]\n","# [1 1 4 ... 2 4 2]]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["A Schedule is *valid* as long as no employee works two consecutive shifts. Get the row indices of all *valid* schedules."],"metadata":{"id":"w9EsBXWUhpCa"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-numpy/proficient/taco-truck/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/advanced/class-transitions.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"class-transitions.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Class Transitions](https://www.practiceprobs.com/problemsets/python-pandas/advanced/class-transitions/)\n","\n","You have a DataFrame called `schedules` that represents the daily schedule of each student in a school. For example, If Ryan attends four classes - *math*, *english*, *history*, and *chemistry*, your `schedules` DataFrame will have four rows for Ryan in the order he attends each class."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(seed=1234)\n","classes = ['english', 'math', 'history', 'chemistry', 'gym', 'civics', 'writing', 'engineering']\n","\n","schedules = pd.DataFrame({\n"," 'student_id':np.repeat(np.arange(100), 4),\n"," 'class':generator.choice(classes, size=400, replace=True)\n","}).drop_duplicates()\n","schedules['grade'] = generator.integers(101, size=schedules.shape[0])\n","\n","print(schedules)\n","# student_id class grade\n","# 0 0 engineering 86\n","# 3 0 chemistry 75\n","# 4 1 math 85\n","# 5 1 engineering 0\n","# 6 1 english 73\n","# .. ... ... ...\n","# 394 98 writing 16\n","# 395 98 civics 89\n","# 396 99 engineering 90\n","# 398 99 math 55\n","# 399 99 history 31\n","# \n","# [339 rows x 3 columns]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["You have this theory that the sequence of class-to-class transitions affects students' grades. For instance, you suspect Ryan would do better in his Chemistry class if it *immediately* followed his Math class instead of his History class.\n","\n","Determine the average and median Chemistry grade for groups of students based on the class they have immediately prior to Chemistry. Also report how many students fall into each group."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/advanced/class-transitions/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/advanced/ob-gym.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"ob-gym.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [OB-GYM](https://www.practiceprobs.com/problemsets/python-pandas/advanced/ob-gym/)\n","\n","You own a gym 💪🏾 for pregnant women 🤰🏾 called “OB-GYM” and you recently opened a second location. You’d like to analyze its performance, but your reporting software has given you the sales data in an awkward format."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(314)\n","\n","sales = pd.DataFrame({\n"," 'date':pd.date_range(start = '2020-01-01', periods=5).repeat(2),\n"," 'store_id':np.tile([1,2], 5),\n"," 'sales1':np.round(generator.normal(loc=750, scale=20, size=10), 2),\n"," 'sales2':np.round(generator.normal(loc=650, scale=40, size=10), 2),\n"," 'members':generator.integers(low=20, high=25, size=10)\n","})\n","sales.loc[sales.store_id == 2, 'sales1'] = np.nan\n","sales.loc[sales.store_id == 1, 'sales2'] = np.nan\n","\n","print(sales)\n","# date store_id sales1 sales2 members\n","# 0 2020-01-01 1 737.54 NaN 22\n","# 1 2020-01-01 2 NaN 629.00 20\n","# 2 2020-01-02 1 750.75 NaN 23\n","# 3 2020-01-02 2 NaN 699.01 22\n","# 4 2020-01-03 1 750.60 NaN 20\n","# 5 2020-01-03 2 NaN 640.20 24\n","# 6 2020-01-04 1 752.65 NaN 21\n","# 7 2020-01-04 2 NaN 695.64 22\n","# 8 2020-01-05 1 747.02 NaN 20\n","# 9 2020-01-05 2 NaN 632.40 22"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Reshape it into a DataFrame like this\n","\n","```\n","# sales_1 sales_2 members_1 members_2\n","# date\n","# 2020-01-01 737.54 629.00 22 20\n","# 2020-01-02 750.75 699.01 23 22\n","# 2020-01-03 750.60 640.20 20 24\n","# 2020-01-04 752.65 695.64 21 22\n","# 2020-01-05 747.02 632.40 20 22\n","```"],"metadata":{"id":"xTgLfNp1Q1zA"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/advanced/ob-gym/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/advanced/product-volumes.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"product-volumes.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Product Volumes](https://www.practiceprobs.com/problemsets/python-pandas/advanced/product-volumes/)\n","\n","Given a Series of product `descriptions` like “birch table measures 3’x6’x2'”, estimate the volume of each product. (**Note**: 3' means 3 \"feet\" in the [imperial system of units](https://en.wikipedia.org/wiki/Imperial_units).)"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","descriptions = pd.Series([\n"," \"soft and fuzzy teddy bear, product dims: 1'x2'x1', shipping not included\",\n"," \"birch table measures 3'x6'x2'\",\n"," \"tortilla blanket ~ sleep like a fajita ~ 6'x8'x1'\",\n"," \"inflatable arm tube man | 12'x1'x1' when inflated\",\n"," \"dinosaur costume -- 6'x4'x2' -- for kids and small adults\"\n","], dtype='string')"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/advanced/product-volumes/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/advanced/rose-thorn.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"rose-thorn.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Rose Thorn](https://www.practiceprobs.com/problemsets/python-pandas/advanced/rose-thorn/)\n","\n","You developed a multiplayer indie game called 🌹 *Rose Thorn*. Players compete in one of two venues - the ocean or the desert. You track the outcome of five games between three players in a DataFrame called `games`."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","games = pd.DataFrame({\n"," 'bella1': ['2nd', '3rd', '1st', '2nd', '3rd'],\n"," 'billybob': ['1st', '2nd', '2nd', '1st', '2nd'],\n"," 'nosoup4u': ['3rd', '1st', '3rd', '3rd', '3rd'],\n"," 'venue': ['desert', 'ocean', 'desert', 'ocean', 'desert']\n","})\n","\n","print(games)\n","# bella1 billybob nosoup4u venue\n","# 0 2nd 1st 3rd desert\n","# 1 3rd 2nd 1st ocean\n","# 2 1st 2nd 3rd desert\n","# 3 2nd 1st 3rd ocean\n","# 4 3rd 2nd 3rd desert"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Now you want to analyze the data. Convert the `games` DataFrame into a new DataFrame that identifies how many times each (`player`, `placement`) occurs per `venue`, specifically with `venue` as the row index and (`player`, `placed`) as the column *MultiIndex*."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/advanced/rose-thorn/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/advanced/session-groups.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"session-groups.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Session Groups](https://www.practiceprobs.com/problemsets/python-pandas/advanced/session-groups/)\n","\n","You run an ecommerce site called *shoesfordogs.com*. You want to analyze your visitors, so you compile a DataFrame called hits that represents each time a visitor `hit` some page on your site."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","pd.set_option('display.max_columns', 500)\n","pd.set_option('display.width', 1000)\n","\n","generator = np.random.default_rng(90)\n","products = ['iev','pys','vae','dah','yck','axl','apx','evu','wqv','tfg','aur','rgy','kef','lzj','kiz','oma']\n","hits = pd.DataFrame({\n"," 'visitor_id':generator.choice(5, size=20, replace=True) + 1,\n"," 'session_id':generator.choice(4, size=20, replace=True),\n"," 'date_time':pd.to_datetime('2020-01-01') + pd.to_timedelta(generator.choice(60, size=20), unit='m'),\n"," 'page_url':[f'shoesfordogs.com/product/{x}' for x in generator.choice(products, size=20, replace=True)]\n","})\n","hits['session_id'] = hits.visitor_id * 100 + hits.session_id\n","\n","print(hits)\n","# visitor_id session_id date_time page_url\n","# 0 4 400 2020-01-01 00:05:00 shoesfordogs.com/product/pys\n","# 1 2 200 2020-01-01 00:18:00 shoesfordogs.com/product/oma\n","# 2 1 102 2020-01-01 00:48:00 shoesfordogs.com/product/evu\n","# 3 4 403 2020-01-01 00:21:00 shoesfordogs.com/product/oma\n","# 4 2 201 2020-01-01 00:40:00 shoesfordogs.com/product/yck\n","# 5 3 302 2020-01-01 00:33:00 shoesfordogs.com/product/pys\n","# 6 2 203 2020-01-01 00:37:00 shoesfordogs.com/product/rgy\n","# 7 3 302 2020-01-01 00:54:00 shoesfordogs.com/product/tfg\n","# 8 3 302 2020-01-01 00:48:00 shoesfordogs.com/product/kef\n","# 9 4 402 2020-01-01 00:24:00 shoesfordogs.com/product/apx\n","# 10 3 300 2020-01-01 00:49:00 shoesfordogs.com/product/kef\n","# 11 1 101 2020-01-01 00:52:00 shoesfordogs.com/product/iev\n","# 12 3 302 2020-01-01 00:01:00 shoesfordogs.com/product/dah\n","# 13 4 403 2020-01-01 00:02:00 shoesfordogs.com/product/lzj\n","# 14 4 401 2020-01-01 00:42:00 shoesfordogs.com/product/evu\n","# 15 5 500 2020-01-01 00:39:00 shoesfordogs.com/product/apx\n","# 16 5 503 2020-01-01 00:31:00 shoesfordogs.com/product/dah\n","# 17 3 303 2020-01-01 00:01:00 shoesfordogs.com/product/lzj\n","# 18 2 200 2020-01-01 00:16:00 shoesfordogs.com/product/aur\n","# 19 1 100 2020-01-01 00:11:00 shoesfordogs.com/product/apx"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["You suspect that the undocumented third-party tracking system on your website is buggy and sometimes splits one session into two or more *session_ids*. You want to correct this behavior by creating a field called *session_group_id* that stitches broken *session_ids* together.\n","\n","Two session, *A* & *B*, should belong to the same session group if\n","\n","1. They have the same `visitor_id` and\n"," 1. Their hits overlap in time *or*\n"," 2. The latest hit from A is within five minutes of the earliest hit from B, or vice-versa\n","\n","**Associativity applies**. So, if A is grouped with B, and B is grouped with C, then A should be grouped with C as well.\n","\n","Create a column in `hits` called `session_group_id` that identifies which hits belong to the same session group."],"metadata":{"id":"xTgLfNp1Q1zA"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/advanced/session-groups/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/afols.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"afols.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [AFOLs](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/afols/)\n","\n","You're developing the comment system for a social platform for AFOLs (Adult Fans Of Legos). The comment data looks like this."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","comments = pd.DataFrame([\n"," [32, pd.NA, 'Legos are awesome'],\n"," [12, pd.NA, 'Legos are okay..'],\n"," [11, 12, 'Just okay??'],\n"," [4, 12, 'Okay, troll..'],\n"," [31, 4, \"I'm serious\"],\n"," [75, 12, 'yeah, nah'],\n"," [41, 75, 'u from down undah?'],\n"," [5, 41, 'nah, yeah'],\n"," [82, pd.NA, 'I love legos'],\n"," [81, 82, 'U 4 rl?'],\n"," [71, 81, 'no'],\n"," [95, 82, 'Me too!'],\n"," [96, 82, 'same']\n","], columns=['id', 'parent_id', 'comment'])\n","\n","# Make id the index\n","comments.set_index('id', inplace=True)\n","\n","print(comments)\n","# parent_id comment\n","# id \n","# 32 Legos are awesome\n","# 12 Legos are okay..\n","# 11 12 Just okay??\n","# 4 12 Okay, troll..\n","# 31 4 I'm serious\n","# 75 12 yeah, nah\n","# 41 75 u from down undah?\n","# 5 41 nah, yeah\n","# 82 I love legos\n","# 81 82 U 4 rl?\n","# 71 81 no\n","# 95 82 Me too!\n","# 96 82 same"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Each comment can have one or none `parent_id` that identifies its parent comment.\n","\n","Insert a column called `n_descendants` in `comments` that displays how many total comments are nested below each comment. For example, comment 12 has six descendants."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/afols/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/cradle-robbers.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"cradle-robbers.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Cradle Robbers](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/cradle-robbers/)\n","\n","Given a DataFrame of married `couples` and a separate DataFrame with each person’s age, identify “cradle robbers”, people:\n","\n","- who are *at least* 20 years older than their spouse **and**\n","- whose spouse is under the age of 30"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","couples = pd.DataFrame({\n"," 'person1': ['Cody', 'Dustin', 'Peter', 'Adam', 'Ryan', 'Brian', 'Jordan', 'Gregory'],\n"," 'person2': ['Sarah', 'Amber', 'Brianna', 'Caitlin', 'Rachel', 'Kristen', 'Alyssa', 'Morgan']\n","}).convert_dtypes()\n","\n","ages = pd.DataFrame({\n"," 'person': ['Adam', 'Alyssa', 'Amber', 'Brian', 'Brianna', 'Caitlin', 'Cody', 'Dustin', 'Gregory', 'Jordan',\n"," 'Kristen', 'Rachel', 'Morgan', 'Peter', 'Ryan', 'Sarah'],\n"," 'age': [62, 40, 41, 50, 65, 29, 27, 39, 42, 39, 33, 61, 43, 55, 28, 36]\n","}).convert_dtypes()\n","\n","print(couples)\n","# person1 person2\n","# 0 Cody Sarah\n","# 1 Dustin Amber\n","# 2 Peter Brianna\n","# 3 Adam Caitlin\n","# 4 Ryan Rachel\n","# 5 Brian Kristen\n","# 6 Jordan Alyssa\n","# 7 Gregory Morgan\n","\n","print(ages)\n","# person age\n","# 0 Adam 62\n","# 1 Alyssa 40\n","# 2 Amber 41\n","# 3 Brian 50\n","# 4 Brianna 65\n","# 5 Caitlin 29\n","# 6 Cody 27\n","# 7 Dustin 39\n","# 8 Gregory 42\n","# 9 Jordan 39\n","# 10 Kristen 33\n","# 11 Rachel 61\n","# 12 Morgan 43\n","# 13 Peter 55\n","# 14 Ryan 28\n","# 15 Sarah 36"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/cradle-robbers/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/hobbies.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"hobbies.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Hobbies](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/hobbies/)\n","\n","You polled five heterosexual couples on their hobbies."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","couples = pd.DataFrame({\n"," 'man': [\n"," ['fishing', 'biking', 'reading'],\n"," ['hunting', 'mudding', 'fishing'],\n"," ['reading', 'movies', 'running'],\n"," ['running', 'reading', 'biking', 'mudding'],\n"," ['movies', 'reading', 'yodeling']\n"," ],\n"," 'woman': [\n"," ['biking', 'reading', 'movies'],\n"," ['fishing', 'drinking'],\n"," ['knitting', 'reading'],\n"," ['running', 'biking', 'fishing', 'movies'],\n"," ['movies']\n"," ]\n","})\n","\n","print(couples)\n","# man woman\n","# 0 [fishing, biking, reading] [biking, reading, movies]\n","# 1 [hunting, mudding, fishing] [fishing, drinking]\n","# 2 [reading, movies, running] [knitting, reading]\n","# 3 [running, reading, biking, mudding] [running, biking, fishing, movies]\n","# 4 [movies, reading, yodeling] [movies]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["For each couple, determine what hobbies each man has that his wife doesn’t and what hobbies each woman has that her husband doesn’t."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/hobbies/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/humans.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"humans.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Humans](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/humans/)\n","\n","You've developed a 🤖 machine learning model that classifies images. Specifically, it outputs labels with non-negligible probabilities."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import pandas as pd\n","\n","predictions = pd.DataFrame.from_dict({\n"," 'preds': {\n"," 12: \"{'dog': 0.55, 'cat': 0.25, 'squirrel': 0.2}\",\n"," 41: \"{'telephone pole': 0.8, 'tower': 0.1, 'stick': 0.1}\",\n"," 43: \"{'man': 0.65, 'woman': 0.33, 'monkey': 0.02}\",\n"," 46: \"{'waiter': 0.45, 'waitress': 0.30, 'newspaper': 0.15, 'cat': 0.10}\",\n"," 49: \"{'nurse': 0.50, 'doctor': 0.50}\",\n"," 72: \"{'baseball': 0.8, 'basketball': 0.15, 'football': 0.05}\",\n"," 91: \"{'woman': 0.62, 'man': 0.28, 'elephant': 0.10}\"\n"," }\n","})\n","\n","print(predictions)\n","# preds\n","# 12 {'dog': 0.55, 'cat': 0.25, 'squirrel': 0.2}\n","# 41 {'telephone pole': 0.8, 'tower': 0.1, 'stick': 0.1}\n","# 43 {'man': 0.65, 'woman': 0.33, 'monkey': 0.02}\n","# 46 {'waiter': 0.45, 'waitress': 0.30, 'newspaper': 0.15, 'cat': 0.10}\n","# 49 {'nurse': 0.50, 'doctor': 0.50}\n","# 72 {'baseball': 0.8, 'basketball': 0.15, 'football': 0.05}\n","# 91 {'woman': 0.62, 'man': 0.28, 'elephant': 0.10}"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["*Each row in predictions represents predictions for a different image.*\n","\n","Insert a column called `prob_human` that calculates the probability each image represents a human. You can use the following list of strings to identify `human` labels."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"code","source":["humans = ['doctor', 'man', 'nurse', 'teacher', 'waiter', 'waitress', 'woman']"],"metadata":{"id":"c-K2VRi0Oct3","executionInfo":{"status":"ok","timestamp":1650244315998,"user_tz":300,"elapsed":3,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/humans/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/party-time.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"party-time.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Party Time](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/party-time/)\n","\n","Whenever your friends John and Judy visit you together, y’all have a party 🥳. Given a DataFrame with 10 rows representing the next 10 days of your schedule and whether John and Judy are scheduled to make an appearance, insert a new column called `days_til_party` that indicates how many days until the next party."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(123)\n","df = pd.DataFrame({\n"," 'john': generator.choice([True, False], size=10, replace=True),\n"," 'judy': generator.choice([True, False], size=10, replace=True)\n","})\n","print(df)\n","# john judy\n","# 0 True True\n","# 1 False False\n","# 2 False True\n","# 3 True False\n","# 4 False True\n","# 5 True True\n","# 6 True False\n","# 7 True False\n","# 8 True False\n","# 9 True False"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["`days_til_party` should be 0 on days when a party occurs, 1 on days when a party doesn’t occur but will occur the next day, etc."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/party-time/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/potholes.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"potholes.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Potholes](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/potholes/)\n","\n","Fed up with your city’s roads, you go around collecting data on `potholes` in your area. Due to an unfortunate ☕ coffee spill, you lost bits and pieces of your data."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","potholes = pd.DataFrame({\n"," 'length':[5.1, np.nan, 6.2, 4.3, 6.0, 5.1, 6.5, 4.3, np.nan, np.nan],\n"," 'width':[2.8, 5.8, 6.5, 6.1, 5.8, np.nan, 6.3, 6.1, 5.4, 5.0],\n"," 'depth':[2.6, np.nan, 4.2, 0.8, 2.6, np.nan, 3.9, 4.8, 4.0, np.nan],\n"," 'location':pd.Series(['center', 'north edge', np.nan, 'center', 'north edge', 'center', 'west edge',\n"," 'west edge', np.nan, np.nan], dtype='string')\n","})\n","\n","print(potholes)\n","# length width depth location\n","# 0 5.1 2.8 2.6 center\n","# 1 NaN 5.8 NaN north edge\n","# 2 6.2 6.5 4.2 \n","# 3 4.3 6.1 0.8 center\n","# 4 6.0 5.8 2.6 north edge\n","# 5 5.1 NaN NaN center\n","# 6 6.5 6.3 3.9 west edge\n","# 7 4.3 6.1 4.8 west edge\n","# 8 NaN 5.4 4.0 \n","# 9 NaN 5.0 NaN "],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Given your DataFrame of pothole measurements, discard rows where more than half the values are `NaN`, elsewhere impute `NaN`s with the average value per column unless the column is non-numeric, in which case use the mode."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/potholes/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/dataframe/vending-machines.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"vending-machines.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Vending Machines](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/vending-machines/)\n","\n","You own a collection of vending machines, and you want to evaluate your inventory. Given a DataFrame of (machine, product, stock), determine the number of machines carrying each product and how many of them are out of stock."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","machine_products = pd.DataFrame({\n"," 'machine': ['abc', 'abc', 'def', 'def', 'def', 'ghi'],\n"," 'product': ['skittles', 'soap', 'soap', 'm&ms', 'skittles', 'm&ms'],\n"," 'stock': [10, 0, 15, 2, 0, 3]\n","})\n","print(machine_products)\n","# machine product stock\n","# 0 abc skittles 10\n","# 1 abc soap 0\n","# 2 def soap 15\n","# 3 def m&ms 2\n","# 4 def skittles 0\n","# 5 ghi m&ms 3"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a new DataFrame with product as the row index, and calculated columns `n_machines` and `n_machines_empty`."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/dataframe/vending-machines/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/final-boss/concerts.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"concerts.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Concerts](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/concerts/)\n","\n","Given a dataset of `concerts`, count the number of concerts per (`artist`, `venue`), per `yearmonth`. Make the resulting table be a wide table - one row per `yearmonth` with a column for each unique (`artist`, `venue`) pair. Use the cross product of the `artists` and `venues` Series to determine which (`artist`, `venue`) pairs to include in the result."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(1357)\n","artists = ['Mouse Rat', 'Binary Brothers', 'Lady Gigabyte', 'The Rolling Sums']\n","venues = ['Super Dome', 'STAPLES Center', 'Madison Square Garden']\n","\n","concerts = pd.DataFrame({\n"," 'artist':generator.choice(['Mouse Rat', 'Binary Brothers', 'Lady Gigabyte', 'Just-in-Timeberlake'], size=200, replace=True),\n"," 'venue':generator.choice(venues + ['Red Rocks'], size=200, replace=True),\n"," 'date':pd.to_datetime('2020-01-01') + pd.to_timedelta(generator.choice(365, size=200, replace=True), unit='D'),\n","}).drop_duplicates().convert_dtypes()\n","\n","print(concerts)\n","# artist venue date\n","# 0 Binary Brothers STAPLES Center 2020-04-10\n","# 1 Binary Brothers STAPLES Center 2020-07-31\n","# 2 Mouse Rat Madison Square Garden 2020-06-21\n","# 3 Mouse Rat Red Rocks 2020-04-17\n","# 4 Binary Brothers Red Rocks 2020-10-05\n","# .. ... ... ...\n","# 195 Lady Gigabyte Red Rocks 2020-08-10\n","# 196 Mouse Rat Madison Square Garden 2020-06-30\n","# 197 Binary Brothers Super Dome 2020-05-02\n","# 198 Just-in-Timeberlake Madison Square Garden 2020-06-21\n","# 199 Binary Brothers Madison Square Garden 2020-04-14\n","# \n","# [200 rows x 3 columns]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/concerts/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/final-boss/covid-tracing.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"covid-tracing.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [COVID Tracing](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/covid-tracing/)\n","\n","You track the whereabouts of 100 individuals in a DataFrame called `whereabouts`. Each person has a corresponding list of `place` ids indicating the places they’ve visited in the recent week. You also track which places have been exposed to COVID-19 in a list called `exposed` 😷."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","# exposed places\n","exposed = [0,5,9]\n","\n","# whereabouts of each person\n","generator = np.random.default_rng(2468)\n","Nplaces = 10\n","Npersons = 10\n","place_ids = np.arange(Nplaces)\n","visits = generator.choice(place_ids, size=3*Nplaces, replace=True)\n","split_idxs = np.sort(generator.choice(len(visits), size=9, replace=True))\n","whereabouts = pd.DataFrame({\n"," 'person_id': range(Npersons),\n"," 'places': [np.unique(x).tolist() for x in np.array_split(visits, split_idxs)]\n","})\n","\n","print(whereabouts)\n","# person_id places\n","# 0 0 [3, 4, 5, 6]\n","# 1 1 []\n","# 2 2 [3]\n","# 3 3 [6, 8, 9]\n","# 4 4 [3]\n","# 5 5 [0, 2, 5, 6, 7, 8]\n","# 6 6 [2, 7]\n","# 7 7 [0, 5, 8, 9]\n","# 8 8 [2, 7, 9]\n","# 9 9 [0, 5, 8, 9]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["For each person, identify the places they visited which have been exposed. Make this a new list-column in `whereabouts` called `exposures`."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/covid-tracing/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/final-boss/family-iq.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"family-iq.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Family IQ](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/family-iq/)\n","\n","Define a person’s Family IQ Score as\n","\n","FamilyIQ = 0.5*IQ + 0.5*RelativesIQ\n","\n","where RelativesIQ is the average IQ score of that person’s parents, full siblings, and children.\n","\n","Given a dataset of people and their IQ scores, determine who has the highest FamilyIQ."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(2718)\n","persons = pd.DataFrame({\n"," 'id': [ 2, 3, 8, 12, 14, 15, 17, 32, 35, 41, 60, 64, 83, 98],\n"," 'mom_id': [35, 41, pd.NA, 35, 41, 2, pd.NA, pd.NA, pd.NA, pd.NA, 8, 12, 35, 2],\n"," 'dad_id': [17, 8, pd.NA, 17, 8, 32, pd.NA, pd.NA, pd.NA, pd.NA, pd.NA, 14, 17, 14],\n"," 'IQ': np.round(generator.normal(loc=100, scale=20, size=14))\n","})\n","\n","print(persons)\n","# id mom_id dad_id IQ\n","# 0 2 35 17 106.0\n","# 1 3 41 8 99.0\n","# 2 8 56.0\n","# 3 12 35 17 110.0\n","# 4 14 41 8 104.0\n","# 5 15 2 32 109.0\n","# 6 17 99.0\n","# 7 32 90.0\n","# 8 35 80.0\n","# 9 41 52.0\n","# 10 60 8 97.0\n","# 11 64 12 14 87.0\n","# 12 83 35 17 138.0\n","# 13 98 2 14 97.0"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["**Note**\n","\n","A *full sibling* of a person is someone who shares the same mom and dad."],"metadata":{"id":"-RxOboIvUXmV"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/family-iq/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/final-boss/pickle.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"pickle.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Pickle](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/pickle/)\n","\n","Given a Series called `pickle`, replace `NaN`s using the following algorithm.\n","\n","```\n","for each NaN:\n"," get the nearest non NaN value before and after it\n"," if both of those values exist:\n"," replace NaN with the minimum of those two non NaN values\n"," else:\n"," replace NaN with the nearest non NaN value\n","```"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","pickle = pd.Series([1.5, np.nan, 2.3, np.nan, np.nan, -3.9, np.nan, 4.5, np.nan, np.nan, np.nan, 1.9, np.nan])\n","\n","print(pickle)\n","# 0 1.5\n","# 1 NaN\n","# 2 2.3\n","# 3 NaN\n","# 4 NaN\n","# 5 -3.9\n","# 6 NaN\n","# 7 4.5\n","# 8 NaN\n","# 9 NaN\n","# 10 NaN\n","# 11 1.9\n","# 12 NaN\n","# dtype: float64"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/pickle/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/final-boss/tv-commercials.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"tv-commercials.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [TV Commercials](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/tv-commercials/)\n","\n","You own a national restaurant chain called Applewasps. To increase sales, you decide to launch a multi-regional television marketing campaign.\n","\n","At the end of the campaign you have a table of `commercials` indicating when and where each commercial aired, and a table of `sales` indicating when and where customers generated sales."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(5555)\n","regions = ['north', 'south', 'east', 'west']\n","\n","commercials = pd.DataFrame({\n"," 'commercial_id': range(10),\n"," 'region': generator.choice(regions, size=10),\n"," 'date_time': pd.to_datetime('2020-01-01') + pd.to_timedelta(generator.integers(240, size=10), unit='h')\n","})\n","\n","sales = pd.DataFrame({\n"," 'sale_id': range(10),\n"," 'region': generator.choice(regions, size=10),\n"," 'date_time': pd.to_datetime('2020-01-01') + pd.to_timedelta(generator.integers(240, size=10), unit='h'),\n"," 'revenue': np.round(generator.normal(loc=20, scale=5, size=10), 2)\n","})\n","\n","print(commercials)\n","# commercial_id region date_time\n","# 0 0 west 2020-01-10 12:00:00\n","# 1 1 north 2020-01-10 16:00:00\n","# 2 2 south 2020-01-09 01:00:00\n","# 3 3 east 2020-01-10 19:00:00\n","# 4 4 south 2020-01-08 22:00:00\n","# 5 5 east 2020-01-03 02:00:00\n","# 6 6 south 2020-01-07 15:00:00\n","# 7 7 west 2020-01-05 22:00:00\n","# 8 8 east 2020-01-03 04:00:00\n","# 9 9 west 2020-01-05 04:00:00\n","\n","print(sales)\n","# sale_id region date_time revenue\n","# 0 0 west 2020-01-05 08:00:00 20.14\n","# 1 1 east 2020-01-08 22:00:00 22.98\n","# 2 2 south 2020-01-07 21:00:00 22.98\n","# 3 3 west 2020-01-05 17:00:00 16.82\n","# 4 4 west 2020-01-02 12:00:00 20.47\n","# 5 5 east 2020-01-10 09:00:00 26.93\n","# 6 6 north 2020-01-08 19:00:00 20.25\n","# 7 7 south 2020-01-01 08:00:00 23.38\n","# 8 8 south 2020-01-01 17:00:00 25.74\n","# 9 9 south 2020-01-10 22:00:00 22.28"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["In order to analyze the performance of each commercial, map each sale to the commercial that aired prior to the sale, in the same region."],"metadata":{"id":"YAl208zxT1Wp"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/final-boss/tv-commercials/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/series/baby-names.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"baby-names.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Baby Names](https://www.practiceprobs.com/problemsets/python-pandas/series/baby-names/)\n","\n","You and your spouse decided to let the internet name your next child. You’ve asked the great people of the web to submit their favorite names, and you’ve compiled their submissions into a Series called `babynames`."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","babynames = pd.Series([\n"," 'Jathonathon', 'Zeltron', 'Ruger', 'Phreddy', 'Ruger', 'Chad', 'Chad',\n"," 'Ruger', 'Ryan', 'Ruger', 'Chad', 'Ryan', 'Phreddy', 'Phreddy', 'Phreddy',\n"," 'Mister', 'Zeltron', 'Ryan', 'Ruger', 'Ruger', 'Jathonathon',\n"," 'Jathonathon', 'Ruger', 'Chad', 'Zeltron'], dtype='string')"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Determine how many people voted for the names ‘Chad’, ‘Ruger’, and ‘Zeltron’."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/series/baby-names/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/series/bees-knees.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"bees-knees.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Bees Knees](https://www.practiceprobs.com/problemsets/python-pandas/series/bees-knees/)\n","\n","Given, two Series `bees` and `knees`, if the ith value of `bees` is NaN, double the ith value inside `knees`."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","bees = pd.Series([True, True, False, np.nan, True, False, True, np.nan])\n","knees = pd.Series([5,2,9,1,3,10,5,2], index = [7,0,2,6,3,5,1,4])\n","\n","print(bees)\n","# 0 True\n","# 1 True\n","# 2 False\n","# 3 NaN\n","# 4 True\n","# 5 False\n","# 6 True\n","# 7 NaN\n","# dtype: object\n","\n","print(knees)\n","# 7 5\n","# 0 2\n","# 2 9\n","# 6 1\n","# 3 3\n","# 5 10\n","# 1 5\n","# 4 2\n","# dtype: int64"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/series/bees-knees/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/series/car-shopping.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"car-shopping.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Car Shopping](https://www.practiceprobs.com/problemsets/python-pandas/series/car-shopping/)\n","\n","After accidentally leaving an ice chest of fish and shrimp in your car for a week while you were on vacation, you’re now in the market for a new vehicle 🚗. Your insurance didn’t cover the loss, so you want to make sure you get a good deal on your new car.\n","\n","Given a Series of car `asking_prices` and another Series of car `fair_prices`, determine which cars for sale are a good deal. In other words, identify cars whose asking price is less than their fair price."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","asking_prices = pd.Series([5000, 7600, 9000, 8500, 7000], index=['civic', 'civic', 'camry', 'mustang', 'mustang'])\n","fair_prices = pd.Series([5500, 7500, 7500], index=['civic', 'mustang', 'camry'])\n","\n","print(asking_prices)\n","# civic 5000\n","# civic 7600\n","# camry 9000\n","# mustang 8500\n","# mustang 7000\n","# dtype: int64\n","\n","print(fair_prices)\n","# civic 5500\n","# mustang 7500\n","# camry 7500\n","# dtype: int64"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["The result should be a **list of integer indices** corresponding to the good deals in `asking_prices`."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/series/car-shopping/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/series/fair-teams.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"fair-teams.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Fair Teams](https://www.practiceprobs.com/problemsets/python-pandas/series/fair-teams/)\n","\n","You’re organizing a competitive rock-skipping league. 6 coaches and 20 players have signed up. Your job is to randomly and fairly determine the teams, assigning players to coaches. Keep in mind that some teams will have three players and some teams will have four players. Given a Series of `coaches` and a Series of `players`, create a Series of random coach-to-player mappings. The resulting Series should have coach names in its index and corresponding player names in its values."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","coaches = pd.Series(['Aaron', 'Donald', 'Joshua', 'Peter', 'Scott', 'Stephen'], dtype='string')\n","players = pd.Series(['Asher', 'Connor', 'Elizabeth', 'Emily', 'Ethan', 'Hannah', 'Isabella', 'Isaiah', 'James',\n"," 'Joshua', 'Julian', 'Layla', 'Leo', 'Madison', 'Mia', 'Oliver', 'Ryan', 'Scarlett', 'William',\n"," 'Wyatt'], dtype='string')\n","\n","print(coaches)\n","# 0 Aaron\n","# 1 Donald\n","# 2 Joshua\n","# 3 Peter\n","# 4 Scott\n","# 5 Stephen\n","# dtype: string\n","\n","print(players)\n","# 0 Asher\n","# 1 Connor\n","# 2 Elizabeth\n","# 3 Emily\n","# 4 Ethan\n","# 5 Hannah\n","# 6 Isabella\n","# 7 Isaiah\n","# 8 James\n","# 9 Joshua\n","# 10 Julian\n","# 11 Layla\n","# 12 Leo\n","# 13 Madison\n","# 14 Mia\n","# 15 Oliver\n","# 16 Ryan\n","# 17 Scarlett\n","# 18 William\n","# 19 Wyatt\n","# dtype: string"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/series/fair-teams/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-pandas/series/price-gouging.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"price-gouging.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Price Gouging](https://www.practiceprobs.com/problemsets/python-pandas/series/price-gouging/)\n","\n","You suspect your local grocery’s been price gouging the ground beef. You and some friends decide to track the price of ground beef every day for 10 days. You’ve compiled the data into a Series called `beef_prices`, whose index represents the day of each recording."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","generator = np.random.default_rng(123)\n","beef_prices = pd.Series(\n"," data = np.round(generator.uniform(low=3, high=5, size=10), 2),\n"," index = generator.choice(10, size=10, replace=False)\n",")\n","\n","print(beef_prices)\n","# 4 4.36\n","# 8 3.11\n","# 2 3.44\n","# 0 3.37\n","# 6 3.35\n","# 9 4.62\n","# 3 4.85\n","# 5 3.55\n","# 1 4.64\n","# 7 4.78\n","# dtype: float64"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["For example, beef was priced 3.37 on the first day, 4.64 on the second day, etc.\n","\n","Determine which day had the biggest price increase from the prior day."],"metadata":{"id":"b6_u7yFwIsLo"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-pandas/series/price-gouging/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-sparse-matrices/dog-shelter.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"dog-shelter.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Dog Shelter](https://www.practiceprobs.com/problemsets/python-sparse-matrices/dog-shelter/)\n","\n","You operate a dog shelter 🐶, and you're building a model to predict the probability of a dog getting adopted based on its age, weight, and breed. You have the following data."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","import pandas as pd\n","\n","# dog breeds list\n","breeds = [\n"," 'english pointer', 'english setter', 'kerry blue terrier', 'cairn terrier', 'english cocker spaniel',\n"," 'gordon setter', 'airedale terrier', 'australian terrier', 'bedlington terrier', 'border terrier',\n"," 'bull terrier', 'fox terrier (smooth)', 'english toy terrier (black &tan)', 'swedish vallhund',\n"," 'belgian shepherd dog', 'old english sheepdog', 'griffon nivernais', 'briquet griffon vendeen',\n"," 'ariegeois', 'gascon saintongeois', 'great gascony blue', 'poitevin', 'billy', 'artois hound',\n"," 'porcelaine', 'small blue gascony', 'blue gascony griffon', 'grand basset griffon vendeen',\n"," 'norman artesien basset', 'blue gascony basset'\n","]\n","\n","# random generator\n","rng = np.random.default_rng(1)\n","\n","# training DataFrame\n","Ndogs = 10\n","dogs = pd.DataFrame({\n"," 'id': rng.choice(1000000, size=Ndogs, replace=False),\n"," 'age': rng.uniform(low=0, high=16, size=Ndogs).round(0),\n"," 'weight': rng.uniform(low=10, high=115, size=Ndogs).round(1),\n"," 'breed': pd.Categorical(rng.choice(breeds[:25], size=Ndogs, replace=True), categories=breeds),\n"," 'adopted': rng.choice([True, False], size=Ndogs, replace=True)\n","})\n","\n","# Insert some NaNs\n","dogs.iloc[rng.choice(Ndogs, size=int(Ndogs * 0.25), replace=False), 1] = np.nan\n","\n","print(dogs)\n","# id age weight breed adopted\n","# 0 311831 NaN 88.8 english pointer False\n","# 1 473184 9.0 39.4 bull terrier False\n","# 2 822941 5.0 60.9 english toy terrier (black &tan) False\n","# 3 34852 13.0 113.0 australian terrier True\n","# 4 948647 NaN 111.0 kerry blue terrier True\n","# 5 511817 7.0 86.1 bull terrier False\n","# 6 144159 2.0 66.8 old english sheepdog False\n","# 7 755162 6.0 39.1 fox terrier (smooth) False\n","# 8 950457 3.0 26.9 gascon saintongeois True\n","# 9 249228 4.0 111.8 border terrier True"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a compressed sparse column matrix to represent the training features. Be sure to one-hot-encode the dog breeds into indicator columns, one for each possible breed (not just the *observed* breeds 😉).\n","\n","The output matrix should look something like this:\n","\n","```\n"," age weight is_english_pointer is_english_setter ...\n","0 NaN 88.8 1.0 0.0\n","1 9.0 39.4 0.0 0.0\n","2 5.0 60.9 0.0 0.0\n","3 13.0 113.0 0.0 0.0\n","4 NaN 111.0 0.0 0.0\n","...\n","```"],"metadata":{"id":"WFnb1Ne1NTtu"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-sparse-matrices/dog-shelter/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-sparse-matrices/mine-field.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"mine-field.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Mine Field](https://www.practiceprobs.com/problemsets/python-sparse-matrices/mine-field/)\n","\n","You're developing a game called *Mine Field*. In the game, you need to represent a 10,000x10,000 grid of mines, where each cell in the grid has a 0.002 probability of containing a mine. Build a sparse matrix called `minefield` to those specs.\n","\n","**Note**: you anticipate frequently needing to fetch *rows* from minefield."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-sparse-matrices/mine-field/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-sparse-matrices/movie-distance.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"movie-distance.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Movie Distance](https://www.practiceprobs.com/problemsets/python-sparse-matrices/movie-distance/)\n","\n","You're building a Netflix clone. You have a dataset of movie reviews, where each review is a (`user_id`, `movie_id`, `rating`) triplet.\n","\n","- `movie_ids` are integers in the range `[0, Nmovies)`\n","- `user_ids` are integers in the range `[0, Nusers)`\n","- `ratings` are integers in the range `[1, 5]`"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import random\n","\n","Nmovies = 10\n","Nusers = 10\n","Nreviews = 30\n","\n","movie_ids = random.choices(range(Nmovies), k=Nreviews)\n","user_ids = random.choices(range(Nusers), k=Nreviews)\n","ratings = random.choices(range(1,6), k=Nreviews)\n","\n","print(movie_ids)\n","# [4, 9, 8, 7, 3, ... ]\n","\n","print(user_ids)\n","# [1, 7, 4, 1, 2, ... ]\n","\n","print(ratings)\n","# [1, 3, 2, 1, 1, ... ]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["1. Build a compressed sparse matrix where (i,j) gives the ith person's review of movie j.\n","2. Normalize the movie vectors (column vectors) so that each of them has unit length.\n","3. Calculate the Euclidean distance between normalized movie 2 and normalized movie 4.\n","\n","*For example* \n","if our Netflix clone had three users and two movies with a review matrix like this\n","\n","```\n","[[1 0]\n"," [0 1]\n"," [3 0]]\n","```\n","\n","The normalized movie vectors would be\n","\n","```\n","[[0.32 0. ]\n"," [0. 1. ]\n"," [0.95 0. ]]\n","```\n","\n","The Euclidean distance between these two normalized movie vectors is 1.41."],"metadata":{"id":"WFnb1Ne1NTtu"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-sparse-matrices/movie-distance/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-sparse-matrices/puny-computer.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"puny-computer.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Puny Computer](https://www.practiceprobs.com/problemsets/python-sparse-matrices/puny-computer/)\n","\n","Build a compressed sparse row matrix from this file of text\n","\n","**my_screenplay.txt**\n","```\n","hey hey my name is ryan\n","hey ryan my name is marissa\n","it is nice to meet you\n","it is nice to meet you too\n","did you know that seals get seasick if you put them on a boat\n","i am surprised\n","i have lots of other animal facts do you want to hear other animal facts\n","no thanks i have to be somewhere\n","okay can i get your number\n","no\n","```\n","\n","such that:\n","\n","- row i of the matrix represents row i of the file.\n","- column j of the matrix represents the jth unique word observed in the file.\n","- element ij represents the number of times word j was observed in line i.\n","\n","**There’s a catch..**\n","\n","Your computer is so puny that *it can’t fit the entire file into memory at one time*. It can fit each line into memory, just not the entire file.\n","\n"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-sparse-matrices/puny-computer/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /python-sparse-matrices/tinder-coach.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"tinder-coach.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Tinder Coach](https://www.practiceprobs.com/problemsets/python-sparse-matrices/tinder-coach/)\n","\n","You operate an online business called *tindercoach.com* where you give people advice on their Tinder profiles ❤️‍🔥. You have a dictionary of `visits` indicating how many times each `visitor_id` visited each `page` on your site."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import random\n","import string\n","from collections import defaultdict\n","\n","Npages = 10\n","Nvisitors = 10\n","Nvisits = 100\n","\n","random.seed(2357)\n","visitor_ids = list(set(random.randint(1000, 9999) for i in range(Nvisitors)))\n","pages = list(set('tindercoach.com/' + ''.join(random.choices(string.ascii_lowercase, k=3)) for i in range(Nvisits)))\n","\n","visits = defaultdict(int)\n","for i in range(Nvisits):\n"," key = (random.choice(visitor_ids), random.choice(pages))\n"," visits[key] += 1\n","\n","print(visits)\n","# defaultdict(, {\n","# (3654, 'tindercoach.com/bgr'): 1, \n","# (1443, 'tindercoach.com/nky'): 1, \n","# (3654, 'tindercoach.com/wpb'): 1, \n","# ..., \n","# (3181, 'tindercoach.com/jam'): 1, \n","# (5502, 'tindercoach.com/cjp'): 1, \n","# (5502, 'tindercoach.com/tjk'): 1\n","# })"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Convert `visits` into a Compressed Sparse Column (CSC) matrix where element (i,j) stores the number of times visitor i visited page j.\n","\n","Then print the sub-matrix showing how many times visitors 1443, 6584, and 7040 visited pages *tindercoach.com/chl*, *tindercoach.com/nky*, and *tindercoach.com/zmr*."],"metadata":{"id":"WFnb1Ne1NTtu"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/python-sparse-matrices/tinder-coach/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /pytorch/basic-models/pass-or-fail.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"pass-or-fail.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Pass Or Fail](https://www.practiceprobs.com/problemsets/pytorch/basic-models/pass-or-fail/)\n","\n","A class of 100 students takes an exam. At the end of the exam, the students self-report the number of hours they studied 📚 for the exam and the amount of sleep 😴 they got the night before. Here's what the data looks like including the Pass/Fail exam results."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import numpy as np\n","\n","# random number generator\n","rng = np.random.default_rng(123)\n","\n","# data (72 passes / 28 fails)\n","passes_sleep = rng.normal(loc=8, scale=1, size=72)\n","passes_study = rng.normal(loc=12, scale=3, size=72)\n","fails_sleep = rng.normal(loc=6, scale=1.5, size=28)\n","fails_study = rng.normal(loc=6, scale=2, size=28)"],"metadata":{"id":"B8VGFbaFypzq","executionInfo":{"status":"ok","timestamp":1650337860741,"user_tz":300,"elapsed":5,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["## Plot"],"metadata":{"id":"CSmGXRWXytYG"}},{"cell_type":"code","source":["import matplotlib.pyplot as plt\n","\n","fig, ax = plt.subplots(figsize=(8,6))\n","ax.plot(passes_sleep, passes_study, linestyle='None', marker='o', color='g', label='pass')\n","ax.plot(fails_sleep, fails_study, linestyle='None', marker='o', color='r', label='fail')\n","ax.set_xlabel('Sleep Time')\n","ax.set_ylabel('Study Time')\n","ax.legend()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":406},"id":"LWGd9WroyuLz","executionInfo":{"status":"ok","timestamp":1650337861256,"user_tz":300,"elapsed":519,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}},"outputId":"b70e2d93-89ae-4eb0-b3b6-d138eb0f4392"},"execution_count":2,"outputs":[{"output_type":"execute_result","data":{"text/plain":[""]},"metadata":{},"execution_count":2},{"output_type":"display_data","data":{"text/plain":["
"],"image/png":"iVBORw0KGgoAAAANSUhEUgAAAe4AAAFzCAYAAAD47+rLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de5TdZX3v8c93kkmTERiaSy0SZjatFmITJDJRMNSWxirYIB4Pp8rZUCoupoJy0fYgOPV4cJ05C5B1GmKldA5iqG5pNdJSsLWwIjfPotbhIgkG5GhnYrxlCDqAE0hCvuePvYfM7Oy9Z19+99/7tdasPfPbl9/3N9mZ736e5/s8j7m7AABAOnTFHQAAAGgeiRsAgBQhcQMAkCIkbgAAUoTEDQBAipC4AQBIkflxB9CMpUuXeqFQiDsMAAAi8fDDDz/j7stq3ZeKxF0oFDQ6Ohp3GAAARMLMxuvdR1c5AAApQuIGACBFSNwAAKRIKsa4AQD5sm/fPu3cuVMvvvhi3KGEauHChVq+fLm6u7ubfg6JGwCQODt37tThhx+uQqEgM4s7nFC4u3bv3q2dO3fq2GOPbfp5dJUDABLnxRdf1JIlSzKbtCXJzLRkyZKWexVI3ACARMpy0p7WzjWSuAEASBESNwAg9UpbSypsKKjr6i4VNhRU2lqKO6TQkLgBIER5SihxKW0tafDOQY1PjsvlGp8c1+Cdgx3/rsfGxnT88cerWCxqxYoVOvvsszU1NaVPfepTWrNmjVauXKnBwUG5uyRp48aNev3rX68TTjhB73vf+yRJ999/v0488USdeOKJWr16tZ5//vmOr5fEDQAhCSuhYLahLUOa2jc169jUvikNbRnq+LWfeuopXXzxxdq+fbuOOOII3Xjjjfrwhz+sb3/729q2bZv27Nmju+66S5J0zTXX6NFHH9Xjjz+um266SZJ0/fXX67Of/awee+wxPfjgg1q0aFHHMZG4ASAkYSYUHLRjckdLx1txzDHHaO3atZKkc889V9/85jd177336s1vfrNWrVqlb3zjG3riiSckSSeccIKKxaK++MUvav788mzrtWvX6qMf/ag2btyoX/ziF68c7wSJGwBCEmZCwUF9vX0tHW9FddW3meniiy/W5s2btXXrVl144YWvTOf62te+pg996EN65JFHtGbNGu3fv19XXnmlbr75Zu3Zs0dr167Vk08+2XFMJG4ACEmYCQUHDa8bVk93z6xjPd09Gl433PFr79ixQw899JAk6Utf+pJOPfVUSdLSpUv1wgsvaPPmzZKkAwcO6Ic//KFOO+00XXvttZqcnNQLL7yg73//+1q1apU+9rGPac2aNSRuAEiyMBMKDiquKmrkzBH19/bLZOrv7dfImSMqrip2/NrHHXecPvvZz2rFihX6+c9/rosuukgXXnihVq5cqXe84x1as2aNJOnll1/Wueeeq1WrVmn16tW69NJLdeSRR2rDhg1auXKlTjjhBHV3d+uMM87oOCabroZLsoGBAWc/bgBpVNpa0tCWIe2Y3KG+3j4NrxsOJKFk3fbt27VixYpYYxgbG9P69eu1bdu2UM9T61rN7GF3H6j1eNYqB4AQFVcVSdQIFF3lAADUUCgUQm9tt4PEDQBAipC4AQB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Eb+oAJAmJG0ghd39Z0n2S7jOzrSpvirBpxkNM5X3oz5n5PDNbpXIiPaXeS8/xc7NeqtwemPH99M/zK/Hd6u5Xtfn6QG7RVQ6kjJkdZ2avm3HoRJU3RZjp3yStNbPXVp7zKjP7LUlPSVpWKXCTmXWb2W/PeN57K8dPlTTp7pMhXcYWSWfP2HlqsZn1h3QuIFNocQPpc5ikz1S2rt0v6f9JGpz5AHefMLM/kXSbmf1K5fBfuPv3zOxsSRvNrFflvwEbJD1RecyLZvaopG5JF4R1Ae7+XTP7C0l3m1mXKjtP6dAPIACqsDsYAElM8QLSgq5yAABShBY3AAApQosbAIAUIXEDAJAiJG4AAFKExA0AQIqQuAEASBESNwAAKfL/AZmDKQQ5fuMOAAAAAElFTkSuQmCC\n"},"metadata":{"needs_background":"light"}}]},{"cell_type":"markdown","source":["**Design and fit a [logistic regression](https://en.wikipedia.org/wiki/Logistic_function) model to this data**. Be sure to subclass [`nn.Module`](https://pytorch.org/docs/stable/generated/torch.nn.Module.html).\n","\n","Here's some starter code."],"metadata":{"id":"6XffTpTty2Yq"}},{"cell_type":"code","source":["import torch\n","from torch import nn\n","\n","# set random seed for reproducibility\n","torch.manual_seed(0)\n","\n","class LogisticRegression(nn.Module):\n"," \"\"\"\n"," Logistic Regression model of the form 1/(1 + e^-(w1x1 + w2x2 + ...wnxn + b))\n"," \"\"\"\n","\n"," pass"],"metadata":{"id":"r8rounbIzCa7","executionInfo":{"status":"ok","timestamp":1650337869617,"user_tz":300,"elapsed":8364,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":3,"outputs":[]},{"cell_type":"markdown","source":["## Bonus 1\n","\n","Use your fitted model to make predictions on the following test data."],"metadata":{"id":"l2dzMSKHzFmM"}},{"cell_type":"code","source":["test_sleep = np.array([\n"," 7.06, 7.19, 7.59, 8.84, 9.66, 9.72, 8.81,\n"," 8.44, 5.66, 9.13, 8.04, 5.31, 7.07, 8.33, 7.83\n","])\n","test_study = np.array([\n"," 19.89, 13.36, 12.7, 14.1, 14.19, 12.4, 10.88, \n"," 13.09, 7.88, 6.35, 4.89, 6.65, 3.67, 5.79, 8.09\n","])"],"metadata":{"id":"XVs3jgm1zJNd","executionInfo":{"status":"ok","timestamp":1650337869618,"user_tz":300,"elapsed":7,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":4,"outputs":[]},{"cell_type":"markdown","source":["## Bonus 2\n","\n","Draw your fitted model's decision boundary onto the plot above."],"metadata":{"id":"qBiDzUxezJ8g"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0","executionInfo":{"status":"ok","timestamp":1650337869620,"user_tz":300,"elapsed":7,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":5,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/pytorch/basic-models/pass-or-fail/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /pytorch/tensors/fliptate.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"fliptate.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Fliptate](https://www.practiceprobs.com/problemsets/pytorch/tensors/fliptate/)\n","\n","Given an 8x8x3 tensor which represents an image of the number 4,\n","\n","![](https://www.practiceprobs.com/problemsets/pytorch/images/four.png)\n","\n","Flip the image horizontally.\n","\n","![](https://www.practiceprobs.com/problemsets/pytorch/images/four-flipped.png)\n","\n","Then rotate the image clockwise 90 degrees.\n","\n","![](https://www.practiceprobs.com/problemsets/pytorch/images/four-rotated.png)"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import torch\n","\n","r = torch.tensor([\n"," [0,0,0,0,0,0,0,0],\n"," [0,0,0,0,0,0,0,0],\n"," [0,0,1,0,0,1,0,0],\n"," [0,0,1,0,0,1,0,0],\n"," [0,0,1,1,1,1,0,0],\n"," [0,0,0,0,0,1,0,0],\n"," [0,0,0,0,0,1,0,0],\n"," [0,0,0,0,0,1,0,0]\n","], dtype=torch.float32)\n","g = 0.8*r\n","b = 0.5*r\n","img = torch.moveaxis(torch.stack((r,g,b)), 0, -1)\n","\n","print(img.shape)\n","# torch.Size([8, 8, 3]) "],"metadata":{"id":"fuIWanzgwtPP"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/pytorch/tensors/fliptate/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /pytorch/tensors/random-block.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"random-block.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Random Block](https://www.practiceprobs.com/problemsets/pytorch/tensors/random-block/)\n","\n","Create a 10x10 tensor of 32-bit integers filled with zeros. Then select a random 3x3 block inside the tensor and switch the values from 0 to 1.\n","\n","**Bonus**\n","You can interpret this tensor as an image where 0s represent black pixels and 1s represent white pixels. Plot the image."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/pytorch/tensors/random-block/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /pytorch/tensors/vanilla-neural-network.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"vanilla-neural-network.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Vanilla Neural Network](https://www.practiceprobs.com/problemsets/pytorch/tensors/vanilla-neural-network/)\n","\n","Here's a \"vanilla\" 🍦 feed-forward neural network with [logistic activation functions](https://en.wikipedia.org/wiki/Logistic_function) and [softmax](https://en.wikipedia.org/wiki/Softmax_function) applied to the output layer.\n","\n","\n","\n","Given the following `X` and `y` tensors representing training data,"],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["import torch\n","\n","# Make data\n","torch.manual_seed(4321)\n","X = torch.rand(size=(8,2))\n","y = torch.randint(low=0, high=3, size=(8,))\n","\n","print(X)\n","# tensor([[0.1255, 0.5377],\n","# [0.6564, 0.0365],\n","# [0.5837, 0.7018],\n","# [0.3068, 0.9500],\n","# [0.4321, 0.2946],\n","# [0.6015, 0.1762],\n","# [0.9945, 0.3177],\n","# [0.9886, 0.3911]])\n","\n","print(y) \n","# tensor([0, 2, 2, 0, 2, 2, 0, 1])"],"metadata":{"id":"BiiG4lSlxb2G"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["calculate:\n","\n","1. the predictions (forward pass)\n","2. the loss using categorical cross entropy\n","3. the gradient of the loss with respect to the weights and biases"],"metadata":{"id":"heA1LlVtxd7O"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/pytorch/tensors/vanilla-neural-network/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/et.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"et.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [E.T.](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/et/)\n","\n","Here's a quote from [E.T. the Extra-Terrestrial](https://en.wikipedia.org/wiki/E.T._the_Extra-Terrestrial)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"coke. you see, we drink it. it's a, it's a drink. you know, food?\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Capitalize the first letter of each sentence using a single call to [`re.sub()`](https://docs.python.org/3/library/re.html#re.sub).\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquote = \"Coke. You see, we drink it. It's a, it's a drink. You know, food?\""],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/et/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/groundhog-day.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"groundhog-day.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Groundhog Day](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/groundhog-day/)\n","\n","Here's a quote from [Groundhog Day](https://en.wikipedia.org/wiki/Groundhog_Day_(film))."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"\"\"Once a year, the eyes of the nation turn here, to this tiny\n","hamlet in Pennsylvania, to watch a master at work. The master?\n","Punxsutawney Phil, the world's most famous weatherman, the\n","groundhog, who, as legend has it, can predict the coming of an\n","early spring. And here's the big moment we've all been waiting for. Let's just\n","see what Mr. Groundhog has to say. Hey! Over here, you little\n","weasel! Well, that's it. Sorry you couldn't be here in person to\n","share the electric moment. This is one event where television\n","really fails to capture the excitement of thousands of people\n","gathered to watch a large squirrel predict the weather, and\n","I for one am deeply grateful to have been a part of it.\n","Reporting for Channel 9, this is Phil Connors.\n","\"\"\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Find all substrings that, `ignoring case sensitivity`,\n","\n","- begin with one of these words: `['the', 'this', 'to', 'in']`\n","- end with one of these words: `['phil', 'weatherman', 'groundhog', 'pennsylvania', 'master']`\n","- have 30 or fewer characters in between the begin and end word (including spaces and newline characters).\n","\n","Keep the earliest identified, non-overlapping, non-nested substrings when scanning from left to right."],"metadata":{"id":"EKx2LPCviljK"}},{"cell_type":"code","source":["starters = ['the', 'this', 'to', 'in']\n","enders = ['phil', 'weatherman', 'groundhog', 'pennsylvania', 'master']"],"metadata":{"id":"F42RTtdoimTD"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["expected = [\n"," 'to this tiny\\nhamlet in Pennsylvania', \n"," 'to watch a master', \n"," 'The master', \n"," \"the world's most famous weatherman\", \n"," 'the\\ngroundhog', \n"," 'this is Phil'\n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/groundhog-day/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/iron-man.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"iron-man.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Iron Man](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/iron-man/)\n","\n","Here's a quote from [Iron Man](https://en.wikipedia.org/wiki/Iron_Man_(2008_film))."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"i told you, I don’t want to join your super secret boy band.\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Find consecutive pairs of characters such that\n","\n","- each character is a letter in the phrase \"iron man\" (excluding the space)\n","- overlapping pairs are allowed.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["charpairs = [\n"," 'on', # ...I don’t want...\n"," 'an', # ...don’t want to...\n"," 'oi', # ...to join your...\n"," 'in', # ...to join your...\n"," 'an' # ...boy band.\n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/iron-man/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/lord-of-the-rings.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"lord-of-the-rings.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Lord of The Rings](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/lord-of-the-rings/)\n","\n","Here's a quote from [The Lord of the Rings: The Fellowship of the Ring](https://en.wikipedia.org/wiki/The_Lord_of_the_Rings:_The_Fellowship_of_the_Ring)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"Aragorn: If by my life or death I can protect you I will. You have my sword. Legolas: And you have my bow. Gimli: And my ax.\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a list of the weapons that have been offered to Frodo.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["weapons = ['sword', 'bow', 'ax']"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/lord-of-the-rings/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/mean-girls.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"mean-girls.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Mean Girls](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/mean-girls/)\n","\n","Here's a quote from [Mean Girls](https://en.wikipedia.org/wiki/Mean_Girls)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"Principal Duvall: So, uh, how was your summer? Ms Norbury: I got divorced. Principal Duvall: Oh. My carpal tunnel came back. Ms Norbury: I win.\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Build a dictionary of `{character: [list of quotes]}`\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["quotes = {\n"," 'Principal Duvall': [\n"," 'So, uh, how was your summer', \n"," 'Oh. My carpal tunnel came back'\n"," ], \n"," 'Ms Norbury': [\n"," 'I got divorced', \n"," 'I win.'\n"," ]\n","}"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/mean-girls/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/advanced/the-dark-knight.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"the-dark-knight.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [The Dark Knight](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/the-dark-knight/)\n","\n","Here's a quote from [The Dark Knight](https://en.wikipedia.org/wiki/The_Dark_Knight_(film))."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = (\n"," \"Because we have to chase him.Because he's the hero Gotham \"\n"," \"deserves, but not the one it needs right now, so we'll hunt \"\n"," \"him.Because he can take it, because he's not a hero.He's a \"\n"," \"silent guardian, a watchful protector, a Dark Knight.\"\n",")"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Split the string into a list of distinct sentences. Each sentence should end with and include a period.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["quotes = [\n"," 'Because we have to chase him.', \n"," \"Because he's the hero Gotham deserves, but not the one it needs right now, so we'll hunt him.\", \n"," \"Because he can take it, because he's not a hero.\", \n"," \"He's a silent guardian, a watchful protector, a Dark Knight.\"\n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/advanced/the-dark-knight/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/beginner/gone-with-the-wind.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"gone-with-the-wind.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Gone with the Wind](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/gone-with-the-wind/)\n","\n","Here's a quote from [Gone with the Wind](https://en.wikipedia.org/wiki/Gone_with_the_Wind_(film)) 👫."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"Frankly my dear, I don't give a darn.\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Check if it contains\n","\n","- a lowercase letter\n","- followed by a single space\n","- followed by the letter g\n","\n","**Expected Result**\n","\n","Should return `True`."],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/gone-with-the-wind/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/beginner/harry-potter.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"harry-potter.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Harry Potter](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/harry-potter/)\n","\n","Here's some dialogue from [Harry Potter and the Sorcerer's Stone](https://en.wikipedia.org/wiki/Harry_Potter_and_the_Philosopher%27s_Stone_(film))."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quotes = \"\"\"Molly Weasley: Fred, you next.\n","George Weasley: He’s not Fred, I am!\n","Fred Weasley: Honestly, woman. You call yourself our mother.\n","Molly Weasley: Oh, I’m sorry, George.\n","Fred Weasley: I’m only joking, I am Fred!\"\"\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Identify each line spoken by Fred. Then put them in a list. (Note that `quotes` is a multi-line string.)\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["lines = [\n"," 'Fred Weasley: Honestly, woman. You call yourself our mother.', \n"," 'Fred Weasley: I’m only joking, I am Fred!'\n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/harry-potter/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/beginner/spongebob-squarepants.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"spongebob-squarepants.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [SpongeBob SquarePants](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/spongebob-squarepants/)\n","\n","Here are some quotes from [SpongeBob SquarePants](https://en.wikipedia.org/wiki/SpongeBob_SquarePants)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quotes = [\n"," \"A 5 letter word for happiness... MONEY.\",\n"," \"I might as well sleep for 100 years or so.\",\n"," \"Hey Patrick, I thought of something funnier than 24... 25!\",\n"," \"I will have you know that I stubbed my toe last week and only cried for 20 minutes.\",\n"," \"Sandy: Don’t you have to be stupid somewhere else? Patrick: Not until 4.\"\n","]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["For each quote, extract everything before the first occurrence of a digit.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquotes = [\n"," 'A ', \n"," 'I might as well sleep for ', \n"," 'Hey Patrick, I thought of something funnier than ', \n"," 'I will have you know that I stubbed my toe last week and only cried for ', \n"," 'Sandy: Don’t you have to be stupid somewhere else? Patrick: Not until '\n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/spongebob-squarepants/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/beginner/star-wars.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"star-wars.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Star Wars](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/star-wars/)\n","\n","Here's a quote from [Star Wars: Episode II – Attack of the Clones](https://en.wikipedia.org/wiki/Star_Wars:_Episode_II_%E2%80%93_Attack_of_the_Clones)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"\"\"You wanna buy 20 death sticks for 8 dollars?\n","You don't want to sell me 20 death sticks.\n","How about 120 death sticks for 80 dollars?\n","No.\n","9 death sticks for 2 dollars?\n","Yeah I'll go for that.\"\"\""],"metadata":{"id":"ZlHN2R3QaPX3","executionInfo":{"status":"ok","timestamp":1650246559914,"user_tz":300,"elapsed":3,"user":{"displayName":"Ben Gorman","userId":"14173905571034790649"}}},"execution_count":1,"outputs":[]},{"cell_type":"markdown","source":["Alter the quote so that `20 death sticks`, `120 death sticks`, and `9 death sticks` become `some death sticks`.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquote = \"\"\"You wanna buy some death sticks for 8 dollars?\n","You don't want to sell me some death sticks.\n","How about some death sticks for 80 dollars?\n","No.\n","some death sticks for 2 dollars?\n","Yeah I'll go for that.\"\"\""],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/star-wars/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/beginner/the-simpsons.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"the-simpsons.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [The Simpsons](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/the-simpsons/)\n","\n","Here's a quote from [The Simpsons](https://en.wikipedia.org/wiki/The_Simpsons)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = \"Me Fail English?\\nThat's\\tUnpossible.\""],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Fix the errant spaces in the string.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquote = \"Me Fail English? That's Unpossible.\""],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Note that `\\n` is a newline character and `\\t` is a tab character. These become evident when you `print()` them.\n","\n","```\n",">>> print(quote)\n","Me Fail English?\n","That's Unpossible.\n","```"],"metadata":{"id":"7XU3NIjxX5Rw"}},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/beginner/the-simpsons/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/intermediate/its-always-sunny.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"its-always-sunny.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [It's Always Sunny](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/its-always-sunny/)\n","\n","Here's a quote from [It's Always Sunny in Philadelphia](https://en.wikipedia.org/wiki/It%27s_Always_Sunny_in_Philadelphia)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = (\n"," \"That's TA, TR's ex-girlfriend - this is classic TA. TR broke up with TA because MK said that \"\n"," \"she saw TA flirting with WT at a party OK, but she was only doing it to make TR jealous because, you know, \"\n"," \"she thought that TR secretly liked EH, but TR didn't like EH. It was all a bunch of bull.\"\n",")"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["This quote has numerous abbreviated names consisting of two capital letters. For example, \"TR\" stands for \"Trey\".\n","\n","Given the following dictionary of `abbreviation: full name` mappings,"],"metadata":{"id":"B5y8ixGsanj2"}},{"cell_type":"code","source":["abbrevs = {\n"," \"TA\": \"Tammy\",\n"," \"TR\": \"Trey\",\n"," \"MK\": \"Maureen Kinallen\",\n"," \"WT\": \"Walt Timby\",\n"," \"EH\": \"Erin Hannabry\"\n","}"],"metadata":{"id":"7lsg0t6IaocG"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["replace each abbreviation with the person's full name. Assume that some capitalized two-letter words like \"OK\", *which are not abbreviated names*, exist!\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquote = (\n"," \"That's Tammy, Trey's ex-girlfriend - this is classic Tammy. \"\n"," \"Trey broke up with Tammy because Maureen Kinallen said that she \"\n"," \"saw Tammy flirting with Walt Timby at a party OK, but she was only \"\n"," \"doing it to make Trey jealous because, you know, she thought that \"\n"," \"Trey secretly liked Erin Hannabry, but Trey didn't like Erin \"\n"," \"Hannabry. It was all a bunch of bull.\"\n",")"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/its-always-sunny/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/intermediate/legally-blonde.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"legally-blonde.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Legally Blonde](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/legally-blonde/)\n","\n","Here's a quote from [Legally Blonde](https://en.wikipedia.org/wiki/Legally_Blonde)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quote = (\n"," \"Because not I'm a Vanderbilt, suddenly white I'm trash? \"\n"," \"grew I up in Bel Air, Warner. Across the street from Aaron Spelling. \"\n"," \"think I most people would agree that's a lot better than some stinky old Vanderbilt.\"\n",")"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Observe each \"I\" and \"I'm\" in the string. **The word before it should be after it**. For example, \"*Because not I'm*\" should be \"*Because I'm not*\". Fix this.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["newquote = (\n"," \"Because I'm not a Vanderbilt, suddenly I'm white trash? \"\n"," \"I grew up in Bel Air, Warner. Across the street from Aaron Spelling. \"\n"," \"I think most people would agree that's a lot better than some stinky old Vanderbilt.\"\n",")"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/legally-blonde/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} -------------------------------------------------------------------------------- /regular-expressions-in-python/intermediate/napoleon-dynamite.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"napoleon-dynamite.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["[![PracticeProbs](https://d33wubrfki0l68.cloudfront.net/b6800cc830e3fd5a3a4c3d9cfb1137e6a4c15c77/ec467/assets/images/transparent-1.png)](https://www.practiceprobs.com/)"],"metadata":{"id":"t1VEtnSjbu-d"}},{"cell_type":"markdown","source":["# [Napoleon Dynamite](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/napoleon-dynamite/)\n","\n","Here are quotes from [Napoleon Dynamite](https://en.wikipedia.org/wiki/Napoleon_Dynamite)."],"metadata":{"id":"M6yShpelZy-I"}},{"cell_type":"code","source":["quotes = [\n"," \"Tina you fat lard!\",\n"," \"Your mom goes to college.\",\n"," \"How long did it take you to grow that mustache?\",\n"," \"Kip, Bring Me My Chapstick!\",\n"," \"I Caught You A Delicious Bass.\",\n"," \"I Told You! I Spent It With My Uncle In Alaska Hunting Wolverines!\",\n"," \"How Much Do You Want To Bet I Can Throw This Football Over Them Mountains?\",\n"," \"Napoleon, Don't Be Jealous That I've Been Chatting Online With Babes All Day\"\n","]"],"metadata":{"id":"ZlHN2R3QaPX3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["Subset this list down to quotes that meet the following condition:\n","\n","- The first vowel in the quote matches the last vowel in the quote, regardless of character case.\n","\n","**Expected Result**"],"metadata":{"id":"eHsmvgEbWQgu"}},{"cell_type":"code","source":["filtered = [\n"," \"Kip, Bring Me My Chapstick!\", \n"," \"Napoleon, Don't Be Jealous That I've Been Chatting Online With Babes All Day\" \n","]"],"metadata":{"id":"ApRH0t9aXW0x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["---"],"metadata":{"id":"h7D8d-J5cela"}},{"cell_type":"code","source":["# Your brilliant solution here!"],"metadata":{"id":"CWwTWfYCa4k0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["## [See our solution!](https://www.practiceprobs.com/problemsets/regular-expressions-in-python/intermediate/napoleon-dynamite/solution/)"],"metadata":{"id":"bF3kvEc4a4It"}}]} --------------------------------------------------------------------------------