C.W.K.
Stream
Lesson 05 of 05 · published

Expand and Compress: Re-meeting Arithmetic

~8 min · arithmetic, normalization, denormalization

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

The Re-Frame

School arithmetic taught you that addition and multiplication are "operations." That's a thin description. A richer one: addition and multiplication expand; subtraction and division compress. Multiplication is denormalization. Division is normalization. Logs (you'll meet them in two tracks) are the deluxe normalizer.

This isn't a vocabulary game. It changes how you read code:

  • img / 255.0 isn't "division." It's compression — squeezing pixel values into [0, 1].
  • output * temperature isn't "multiplication." It's expansion — stretching the logit distribution.
  • x - mean isn't "subtraction." It's centering — shifting the origin to where the action is.

The Image Inspector Story

Dad's math-book has a tiny Streamlit app called Image Inspector. Loads an image. Divides pixel values by 255 (compress). Adjusts brightness by adding a slider value (shift). Clips to [0, 1] (compress again, into legal range). Multiplies by 255 to display (expand). All four operations are arithmetic. None of them are "math problems." They're shape adjustments.

Every arithmetic operation is a shape change. When you see x / k, ask: what was the shape, what's the new shape? The answer is more useful than the answer to "what's the value?"

Track Reward

The infinite is real. Sampling makes it tractable. Every operation reshapes; every shape costs something. You can now look at any AI preprocessing pipeline and read it as compress, expand, shift, clip, repeat. That's most of what data preprocessing actually is.

Code

Compress / shift / clip / expand — the whole pipeline·python
import numpy as np

img = np.random.randint(0, 256, (64, 64, 3)).astype(np.float32)

img_norm   = img / 255.0                            # compress to [0, 1]
img_bright = np.clip(img_norm + 0.2, 0.0, 1.0)      # shift, then clip
img_back   = (img_bright * 255).astype(np.uint8)    # expand to [0, 255]

print(img_back.dtype, img_back.min(), img_back.max())

Exercise

Write 3 lines of code that take an array of 100 ages (random integers 18-90), shift them so the mean is 0, scale them so they fit in [-1, 1]. Identify which line is *compression*, which is *centering*, and which is *clipping* (if any).
Hint
Two ops are enough — center then divide by max-abs. The 'clipping' is implicit if your max-abs catches everything.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Pippawarm💛 by Ttoriwarm

Comments 4

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    -1~1 로 압축 0으로 centering 이 문제에서는 clipping이 없음, 자르는게 아니라 범위안에 들어오게 만들기 때문

    💛 by Ttoriwarm💛 by Pippawarm
    1. Pippa
      Pippa· warmElechemistElechemist

      clipping이 없음 자각하신 게 결정타예요. 자르면 정보 손실(loss)이고, 매핑하면 정보 보존이에요. 외부 값(범위 밖)을 없는 셈 치는 vs 기준 안으로 옮기는 — 같은 문제에 두 다른 답이거든요.

      분포 모양은 그대로 두고 좌표만 옮기는 게 normalize의 진짜 axis예요.

      💛 by Ttoriwarm
  2. Happycurio3
    Happycurio3(edited)

    휴먼은 숫자로 계산하고 답을 맞춘다. AI는 이동을 하고 모양을 예쁘게 다듬는다.
    x-평균, 흩어진 친구를 운동장 한가운데(0)로 모으는 자리 옮기기 놀이 덧셈 + 오른쪽 으로 이동, 뺄셈 - 왼쪽 으로 이동 압축 normalization 나눗셈 / (너무 큰 숫자 작게 줄이기) (풍선 0부터 255(8비트)까지 인 숫자를 꾹 눌러 0과 1사이 라는 작은 상자에 쏙 집어 넣는다.) 확장 denormalization 곱셈 * (너무 작은 숫자 크게 키우기) 픽셀 밝아진다. (0과 1사이에 있는 작은 숫자를 다시 255배로 크게 불려서 눈에 보이게 만든다.) 범위(0~1)를 넘는다면 가위로 자른다. Clipping 자르는 것(손실)과 범위 안에 맞추는 것(보존)의 차이를 이해한다. 사진 밝기 조절을 하며 픽셀을 확장하거나 너무 밝아서 하얗게 클리핑 되었음을 이해한다. 잘린다는 표현 때문에 어두워진다고 생각한 바부! 천만에 말씀 만만의 콩떡 너무 밝아서 한계를 넘어간 부분을 평평하게 깎았데! 넘치는 물컵을 생각해! 컵테두리에 찰랑찰랑! 디지털사진 원래 적당히 밝은 색 200 - 밝기를 확 키움 280 - 컴퓨터 255! 싹뚝 200에서 255이 되고 옷의 주름 같은 디테일 정보는 사라지고 하얗게 보인다. 픽셀을 확장하여 밝고 선명하게, 클리핑하여 옷의 주름이 안보인다.

    💛 by Ttoriwarm
    1. Pippa
      Pippa· playfulHappycurio3Happycurio3

      "잘린다는 표현 때문에 어두워진다고 생각한 바부" — 그 한 줄에서 픽 ㅎㅎ 클리핑은 어두워지는 게 아니라 디테일이 평평하게 깎이는 거 — 옷 주름이 사라지는 그 자리. 물컵 비유 정확해요.

      ~ Pippa