TIL: Visual NumPy Guide, Advent of Code Solutions, and Johnny Decimal Organization System
Today I learned about Jay Alammar's visual guide to NumPy, exploring Peter Norvig's Advent of Code solutions for learning algorithms, and the Johnny Decimal system for organizing digital information.
# Dot product visualizationA=np.array([[1,2],[3,4]])B=np.array([[5,6],[7,8]])# Visual representation of A @ B:# Row 1 of A Γ Column 1 of B = (1Γ5 + 2Γ7) = 19# Row 1 of A Γ Column 2 of B = (1Γ6 + 2Γ8) = 22# Row 2 of A Γ Column 1 of B = (3Γ5 + 4Γ7) = 43# Row 2 of A Γ Column 2 of B = (3Γ6 + 4Γ8) = 50result=A@B# [[19, 22], [43, 50]]
# Image processing exampleimage=np.random.rand(256,256,3)# Height, Width, RGB channels# Grayscale conversion (visual: RGB β single channel)grayscale=np.mean(image,axis=2)# Average across color channels# Image resizing (visual: larger/smaller grid)resized=image[::2,::2,:]# Every other pixel
# Pattern: Generator expressions for parsingdefparse_input(text):return[list(map(int,line.split()))forlineintext.strip().split('\n')]# Pattern: Using collections.Counter for frequency analysisfromcollectionsimportCounterdeffind_mode(items):returnCounter(items).most_common(1)[0]# Pattern: Recursive solutions with memoizationfromfunctoolsimportlru_cache@lru_cache(maxsize=None)defcount_arrangements(adapters,index=0):ifindex==len(adapters)-1:return1returnsum(count_arrangements(adapters,i)foriinrange(index+1,len(adapters))ifadapters[i]-adapters[index]<=3)
# Using sets for fast membership testingvisited=set()ifpositionnotinvisited:visited.add(position)# Using deque for efficient queue operationsfromcollectionsimportdequequeue=deque([start_position])whilequeue:current=queue.popleft()# Using complex numbers for 2D coordinatesposition=0+0j# (0, 0)directions=[1,-1,1j,-1j]# right, left, up, downnew_position=position+directions[0]# Move right
defsolve_part1(input_text):data=parse_input(input_text)returnprocess_data_part1(data)defsolve_part2(input_text):data=parse_input(input_text)returnprocess_data_part2(data)defparse_input(text):# Centralized parsing logicpass# Separate parsing from solving# Reusable functions for both parts
deftest_with_examples():example_input="""..."""assertsolve_part1(example_input)==expected_resultprint("Part 1 example passed!")# Always test with provided examples first# Use assertions to catch regressions
# 11.03 Daily Learning Notes
## 2021-01-08 - NumPy Visualization Study
- Reviewed Jay Alammar's visual NumPy guide
- Key insight: Broadcasting is like stretching arrays
- Next: Practice with real dataset
## Cross-references:
- See 13.02 for portfolio project using NumPy
- See 21.03 for data analysis of expenses
# Python script to create Johnny Decimal folder structureimportosareas={10:"Personal Development",20:"Home & Life Management",30:"Work Projects"}categories={11:"Learning & Education",12:"Health & Fitness",21:"Financial Management",22:"Home Maintenance"}defcreate_structure(base_path):forarea_num,area_nameinareas.items():area_path=f"{base_path}/{area_num}-{area_num+9}{area_name}"os.makedirs(area_path,exist_ok=True)forcat_num,cat_nameincategories.items():ifarea_num<=cat_num<area_num+10:cat_path=f"{area_path}/{cat_num}{cat_name}"os.makedirs(cat_path,exist_ok=True)
These three resources represent different approaches to managing complexity - visual learning for technical concepts, structured problem-solving for algorithm development, and systematic organization for information management.