Don't Use This Code—Expert Training & Consulting Profile picture
Python Training and Consulting Accepting new clients - DMs are open @dontusethiscode Subscribe to DUTC Weekly! https://t.co/Cl6s6vkwaO

Dec 2, 2021, 9 tweets

🧵 Our head instructor @dontusethiscode is trying #AdventOfCode using only NumPy/pandas.

Let's see how he does!

❤️ Like → “Neat!”/“That's how I did it!”
🔄 RT → “Hold up; why'd he do it that way…?”
💬 Comment → “Gimme the step-by-step…”
😎 QT → “I did it better!”

Day #1, Part #1

Summary:
- `Series` operations

Code: gist.github.com/dutc/c08a1fc2c…

Day #1, Part #2

Summary:
- `.rolling` window calculation pandas.pydata.org/docs/reference…

Code: gist.github.com/dutc/c08a1fc2c…

Day #2, Part #1

Summary:
- `complex128` as 2D position vector
- aggregate mapping via `Series.loc`
- `Categorical` for fast mapping pandas.pydata.org/docs/reference…

Code:
gist.github.com/dutc/c08a1fc2c…

Day #2, Part #2

Summary:
- `MultiIndex` columns
- common indexing: `RangeIndex` for event #
- `Int64` buggy!

Steps:
① compute aim, using index-alignment and `Series.loc` mapping
② compute position from aim & distance `.cumsum`
③ `.product`

Code:
gist.github.com/dutc/c08a1fc2c…

Day #3, Part #1

Summary:
- NumPy structured array
- `numpy.unique(…, return_counts=True)`

Code:
gist.github.com/dutc/c08a1fc2c…

Day #3, Part #2

Summary:
- `itertools.dropwhile` & generator for iterative search

Code:
gist.github.com/dutc/c08a1fc2c…

Day #4, Parts #1 & #2

Summary:
- @xarray_dev → extremely readable array code
- majority of code is data ingestion & structuring
- good structure → easy processing (!!)
- good structure → easy reporting (!!) †

† “Answer all questions at once.”

Code:
gist.github.com/dutc/c08a1fc2c…

Day #5, Parts #1 & #2

Summary:
- @xarray_dev for readability & @numpy_team for raw manipulation
- NumPy structured array
- stay within “restricted computation domain” with indexing tricks, `numpy.put`, &c.
- trade memory for analytical flexibility

Code:
gist.github.com/dutc/c08a1fc2c…

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling